On 5/27/10 Thu May 27, 2010 9:27 AM, "Robert Morales"
<[email protected]> scribbled:
> Hi,
>
> I want my code to execute the unix free command in order to analyze
> the memory state, and issue a warning if the cached memory increases.
> I don`t know what I did wrong, but this is what I got for now:
>
> #! /usr/bin/perl
> use warnings;
> use strict;
>
> # return codes
> $ok = 0;
> $warning = 1;
> $critical = 2;
>
> open(my $memory, "free") or die "Error: $!"; # running unix command "free"
The above line will attempt to open a file "free" in the current directory.
If you want to pipe output from a command into your program, the name should
end in '|':
open( my $memory, "free|") ...
or, better, use the 3-argument version of open:
open( my $memory, '-|', 'free' ) ...
See 'perldoc -f open' for details.
>
> $regex = "^((?!total).)*$";
>
> while (my $line = $vgs){
The above should be:
while( my $line = <$memory> ) {
>
> if ($line =~ m/$regex/){
> chomp $line;
> my @array = split /\s+/, $line;
> if ($array[6] >= "867580"){
> print "$warning\n";
> }elsif ($array[6] >= "689967"){
> print "$critical\n";
> }else{
> print "$ok\n";
> }
> }
> }
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/