Robert Morales wrote:
Ok, now I added the:
my $regex = "^((?!total).)*\$";
I also removed the " " from the numbers in the if test:
if ($array[6] >= 867580){
The error msg I get this time, is like this:
r...@user# ./script.pl
0
Use of uninitialized value $array[6] in numeric ge (>=) at ./script.pl line
21, <$memory> line 3.
Use of uninitialized value $array[6] in numeric ge (>=) at ./script.pl line
23, <$memory> line 3.
0
Use of uninitialized value $array[6] in numeric ge (>=) at ./script.pl line
21, <$memory> line 4.
Use of uninitialized value $array[6] in numeric ge (>=) at ./script.pl line
23, <$memory> line 4.
0
I appreciate the help :)
If 'free' on your system is the same as 'free' on my system then there
is only one line with seven fields so the other lines will try to
compare an undefined value with a number and produce that warning
message. This should probably work better:
#!/usr/bin/perl
use warnings;
use strict;
# Nagios return codes
my $ok = 0;
my $warning = 1;
my $critical = 2;
my $unknown = 3;
# running unix command "free"
open my $memory, '-|', 'free' or die "Cannot open pipe from 'free' $!";
while ( <$memory> ) {
my @fields = split;
next unless @fields == 7;
if ( $array[ 6 ] >= 867_580 ) {
print "$warning\n";
}
elsif ( $array[ 6 ] >= 689_967 ) {
print "$critical\n";
}
else {
print "$ok\n";
}
}
close $memory or warn $! ? "Error closing 'free' pipe: $!"
: "Exit status $? from 'free'";
__END__
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/