On Thursday 27 May 2010 19:27:46 Robert Morales wrote:
> 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"
> 

This command opens the file "free" for reading, not the output of the UNIX 
command "free". Use three args open and do:

open (my $memory, "-|", "free") or ....

Regards,

        Shlomi Fish

> $regex = "^((?!total).)*$";
> 
> while (my $line = $vgs){

What does that line do?

> 
>     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";
>         }
>     }
> }

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to