Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How do I convert this perl regexp to include all file systems?
Okay geniuses, help me out here... Basically I have a script monitoring my file systems for utilization over X percent. Right now, I think it only monitor "/" and not any other filesystem. How do I convert the following script to also monitor (for example) /mnt/nas or /home?
---- code ---
open(DF, $df . '|') or die "Can't read from Disk Free command '$df': $!\n";
my ($buf, $add);
while (<DF>) {
$buf .= $_;
if ( /.*\s.*\s.*\s.*\s(.*)%\s\/$/ ) {
if ( $1 >= $maxdiskutil ) {
$add++;
}
}
}#while
close(DF);
--- /code ---
Output from the df command (example):
#>df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 124G 34G 83G 30% /
/dev/sda2 2.0G 36M 1.9G 2% /tmp
tmpfs 2.0G 0 2.0G 0% /dev/shm
Keep in mind, I still want to specify which filesystems. For example, I want to list all the important filesystems and ignore the other ones like /tmp.
2 Answers
- martinthurnLv 610 years ago
You'll have to show us the output of your df command in order for us to help you...
But perhaps if you just delete the $ from the regexp it will do what you want...
- 10 years ago
if ( /(\/dev\/.*)\s.*\s.*\s.*\s(.*)%\s(\/.*$)/ ) {
But to make it work the way you want I would add more checks like this:
open(DF, $df . '|') or die "Can't read from Disk Free command '$df': $!\n";
my ($buf, $add);
while (<DF>) {
#$1 = filesystem ie /dev/md1
#$2 = use %
#$3 = mount point
if ( /(\/dev\/.*)\s.*\s.*\s.*\s(.*)%\s(\/.*$)/ ) {
# check only these mount points
if ( $3 =~ /(\/|\/boot)$/ ) {
$buf .= $_;
if ( $2 >= $maxdiskutil ) {
$add = 1;
}
}
}
}
close(DF);