kwalike57 said:
I need to use Perl to read through log output from a df -k command on
a Unix server, for each line in the log where the value for %Used is
greater than 60% I need to write that line of the log out to another
text file. The header %Used is located on the line above the actual
value, like this:
How would I capture and evaluate only the %Used value and no other
values in that line?
The 60% occurs first in the value line followed by a percent value for
inodes used.
open my $ph, '-|', 'df', '-k' or die "Cannot open pipe from 'df' $!";
<$ph> =~ /%used?\b|\bused?%/i and my $pos = $-[0];
/\A.{$pos}\s*(\d+)/ && $1 > 60 && print while <$ph>;
close $ph or warn $! ? "Error closing 'df' pipe: $!"
: "Exit status $? from 'df'";
That's pretty nifty (no sarcasm intended). However, have you tried
it?
I don't get what I expect. Perhaps the issues are on my end though...
bash-2.03$ ./df.pl
df: cannot statvfs /foswbdmmk1/install: Permission denied
df: cannot statvfs /foswbdmmk1/admin: Permission denied
df: cannot statvfs /foswbdmmk1/was: Permission denied
df: cannot statvfs /foswbdmmk1/stag: Permission denied
df: cannot statvfs /foswbdmmk1/prev: Permission denied
df: cannot statvfs /foswbdmmk1/log: Permission denied
df: cannot statvfs /foswbdmmk1/ihs: Permission deniedUse of
uninitialized value in concatenation (.) or string at ./df.pl line 10,
<$ph> line 2.
df: cannot statvfs /foswbdmmk1/app: Permission denied
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 3.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 4.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 5.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 6.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 7.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 8.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 9.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 10.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 11.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 12.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 13.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 14.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 15.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 16.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 17.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 18.