Someone kindly pointed out that perldoc is a handy thing.

- Tony

-----Original Message-----
From: Akens, Anthony 
Sent: Tuesday, January 20, 2004 4:31 PM
To: [EMAIL PROTECTED]
Subject: RE: Use of "System"


Sorry all, I seem to be having problems with our company's 
chosen mail client (Outlook).  Trying this again, hopefuly 
it will preserve my EOL characters this time.

- Tony



I'm attempting to use the following code on an AIX machine to 
monitor the error log (using the errpt command).

I'm sure parts of it are very ugly, but it's (mostly) working.

The part that isn't is the foreach loop.  What it's supposed to 
do is as follows:

#read in the "summary" error report, which is in the following 
#format - 
#IDENTIFIER TIMESTAMP  T C RESOURCE_NAME  DESCRIPTION
#AA8AB241   0120143604 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143604 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143604 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143604 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143504 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143504 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120143504 T O OPERATOR       OPERATOR NOTIFICATION
#AA8AB241   0120142304 T O OPERATOR       OPERATOR NOTIFICATION

@errors =system("errpt |head -n $diff_t | tail -n $diff");

foreach $line (@errors){

#I only care about the first field.  There must be a better way!
  ($err_num, undef, undef, undef, undef, undef, undef) = split(" ",
$line); 
#Use the errpt command to "expand" the message.
  $message = system ("errpt -j $err_num -a");
#add the message to a variable for all of the messages
  $errlogl .= $message;
}

Instead, when I run the command with an & to put it in the 
background it does the first system line above (@errors=...) to 
standard out.

Any help, or comments on the rest of the script are appreciated.

-Tony

#!/usr/bin/perl -w

use strict;

# This script will run every [interval] and check the error log # for
new entries.  Upon finding them, it will send an email to #
administrators containing a message indicating the change # in errlog
status, as well as the offending lines. my $lc = -1;  #last count my $tc
= -1; #This count my $interval = 30;  #Interval in seconds my $me =
"Hardware error monitoring"; my $hostname; my $os; my $mailto = "root";
my $diff; my $msg; my $page_msg; my $errlogl; my $line; my $err_num; my
@errors; my $diff_t; my $message;

open (UNAME, "uname -a |") or die "Couldn't fork: $!\n";
( $os, $hostname, undef, undef, undef ) = (split " ", <UNAME>); close
(UNAME);

system ("echo \"$me started.\nThis message goes to $mailto.\" | mail -s
\"Errlog monitoring for $hostname\" $mailto");

while ( 1 ) {
   $tc=`errpt -dH,S,U,O | wc -l`;
   
   if ( $lc == -1 ) {
      $lc=$tc;
   }
   if ( $lc != $tc ) {
      $diff=$tc-$lc;
      $diff_t = $diff + 1;
      $msg="$diff new errors have been found on $hostname";
      $page_msg="$diff new errors have been found on $hostname";
      @errors =system("errpt |head -n $diff_t | tail -n $diff");
      foreach $line (@errors){
          ($err_num, undef, undef, undef, undef, undef, undef) = split("
", $line);
          $message = system ("errpt -j $err_num -a");
          #$message = "Test message\n";
          $errlogl .= $message;
      }
      if ( $tc eq "0" ) {
        $msg="$msg\n Errlog was cleared";
      }else{
         #system ("logger $msg");
         $msg=" $msg \n Errlog details below:\n $errlogl \n";
      }
      system ("echo \"$msg\" | mail -s \"Errlog status change on host
$hostname\" $mailto");
   }
   $lc=$tc;
   $errlogl = "";
   sleep $interval;
}

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



--
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