Tim Wolak wrote:

Hello all,

I have a script that is checking a service to see if its running and that its log file does not contain two error message to confirm that it has not died. However the subrutine is just saying its up when I have put the error message in the last line of the log to make sure it sees that its down. Please have a look at the code snipit and any help would be great.

use strict; use warnings;

always always always!

Thanks,

Tim

sub grepstring {
  open LOG, "tail gw_20050105.log |", or die "Log file not found $!";

It wasn't found? are you sure, what if it found but the permisions won't allow it to be read, what if it was locked? Let $! tell you the exact reason :)


Why are you piping tail's output to LOG?

Why not

 open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";

      while (<LOG>) {
        $newlog = <LOG>;

my $newlog would be better so its in scope, just using $_ would be even better :)


        if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
        exit $exit_codes{'CRITICAL'};
        print "Log entry can not be found GW down!\n";

This will never get printed because its already exited


} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}
} }

How about this:

 open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";
 while(<LOG>) {
     if(/^Read failed on socket/ || /^EFIXException::/) {
         print "Log entry can not be found GW down!\n";
         exit $exit_codes{CRITICAL};
     } else {
         print "GW is UP!\n";
         exit $exit_codes{OK};
     }
 }
 close LOG;

HTH :)

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to