--- Ramprasad A Padmanabhan
<[EMAIL PROTECTED]> wrote:
> On Mon, 2004-10-11 at 06:26, loan tran wrote:
> > 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;
> >
> > ##
>
>
>
> I am not able to get it ?
> Why cant you put This inside your first while loop
>
> 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");
> }
>
>
>
>
> Probably after
> "print "\n $suspend \n";"
>
>
> Bye
> Ram
I have tried your suggestion. Howerver, result i got
is only the first if run ( reciveice only blocking
email).
In my first post I forget a "last" statement in each
if. (b/c I dont want to receive multible emails if
there are multily blocking or suspending procecess.)
So here is the code again:
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);
if ($blk != 0){
print "Alert Blocking processes\n";
system("/usr/bin/mailx -s 'Alert BLOCKING
Process' $receipients < $whodo_out");
last;
}
}#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);
if ($log_suspend eq 'LOG SUSPEND'){
print "Alert! LOG SUSPEND processes\n";
system("/usr/bin/mailx -s 'Alert LOG SUSPEND
Process' $receipients < $whodo_out");
last;
}
}#end while
close FILE;
>
>
>
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>