Hello Perl Gurus,

I wrote a script to search for log suspends and
bloking processes in a text file and send me email if
it find either of them. My codes below work but it's
not efficent. As you can see I open the file and go to
while loop twice. Can someone suggest a better way?
Thanks.
(attached is the text file i open to search.)
Below is my codes:

#!/bin/perl -w
require "/home/sybase/tranl/pl/global.pl";

## Search for blocking process

open (FILE,"<$whodo_out") or die ("Cannot open file:
$!");
while (my $line =<FILE>){
    chomp($line);
    $line =~ s/^\s+//;
    next if ($line =~ /^\D/);
    my $blk = substr($line,40,3);
    print " $blk \n";
    if ($blk != 0){
        print 'Alert! Blocking processes';
        system("/usr/bin/mailx -s 'Alert Blocking
Process' $receipients < $whodo_out");
    }
    print "\n $suspend \n";
    #exit ;
}#end while

close (FILE);

# Search for LOG SUSPEND process

open (FILE,"<$whodo_out") or die ("Cannot open file:
$!");
while (my $line =<FILE>){
    chomp($line);
    $line =~ s/^\s+//;
    next if ($line =~ /^\D/);
    my $log_suspend = substr($line,70,11);
    print  "$log_suspend \n";
    if ($log_suspend eq 'LOG SUSPEND'){
        print 'Alert! LOG SUSPEND processes';
        system("/usr/bin/mailx -s 'Alert LOG SUSPEND
Process' $receipients < $whodo_out");
    }
    
}#end while

close FILE;

##


                
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 
 spid   status       loginame     hostname   blk  program          dbname  cmd         
     cpu    io           
 ------ ------------ ------------ ---------- ---- ---------------- ------- 
---------------- ------ ------------ 
      2 sleeping     NULL                    0                     master  NETWORK 
HANDLER  0      0            
      3 sleeping     NULL                    0                     master  DEADLOCK 
TUNE    0      0            
      4 sleeping     NULL                    0                     master  MIRROR 
HANDLER   0      0            
      5 sleeping     NULL                    0    <astc> master  ASTC HANDLER     0    
  0            
      6 sleeping     NULL                    0                     master  CHECKPOINT 
SLEEP 0      1502134      
      7 sleeping     NULL                    0                     master  HOUSEKEEPER 
     0      886596       
      8 sleeping     NULL                    18                    master  NETWORK 
HANDLER  0      0            
     13 sleeping     loader                  0                     Mills   INSERT      
     2031   9872         
     16 recv sleep   sa           ASDECS04   0    Rapid SQL        Mills   AWAITING 
COMMAND 1      0            
     18 running      sa           titania.ab 0    isql             Mills   SELECT      
     218    0            
     21 sleeping     loader                  0                     Mills   LOG SUSPEND 
     1930   0            

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