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