Lance Prais wrote:
>
> I am experiencing the most bizarre problem with my perl script. I am
> running the below script on windows nt, that may be the root of the
> problem.. The script reads a file and checks to see it the words "Sleeping
> for 10 seconds" appears. If it appears four times in a row it sends a text
> message so, we can correct the problem.
>
> What seems to happen is after the script runs for about 2 months with out
> restarting the box, at some point it starts reading "Sleeping for 1" The
> other thing I notice is when this occurs the output of looks different.
>
> For example:
>
> When it is working it looks like this
> Sleeping for 10 seconds
> Sleeping for 10 seconds
> Sleeping for 10 seconds
> Sleeping for 10 seconds
> Send email
>
> When it is not working it looks like this:
> Sleeping for 1
> Sleeping for 1
> Sleeping for 1
> Sleeping for 1
> END
>
> As you notice there is a tb added to the script.. Anyone have an Idea to why
> this occurring.
It could be because you are assuming that the string you are looking for is always at
the same position in the string.
> Below you will see the script
>
> Thank you in advance for you help
> Lance
>
> #!/usr/bin/perl
#!/usr/bin/perl -w
use strict;
> my $count = 0;
> open MAIL_LOG, ">> siebel_mail.log" or
> die "can't append to siebl_mail.log: $!";
> # do this 7 times
> for (1 .. 7) {
> open OUTPUT, '..\\..\\srvrmgr /ser server.com /e CHK_ENT_PRD /s
> CHK_SBL_PRD /u xxxxxx /p xxxxxxx /c "list tasks for server CHK_SBL_PRD
> component Email Manager" |' or
> die "can't run srvrmgr: $!";
> <OUTPUT> for 1 .. 22; # skip first 22 lines of output
> my $line = substr <OUTPUT>, 106, 22;
^^^^^^^
Is the string always at this position?
> close OUTPUT;
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
> if ($count eq 4)
^^
You should use a numerical operator to compare numbers.
> {
>
> use Mail::Sendmail; #Send and email if there are
> errors
> %mail = ( To => '[EMAIL PROTECTED]',
> From => '[EMAIL PROTECTED]',
> Subject => '',
> Message => 'Email Manager hung on Apollo'
> );
> sendmail(%mail) or die $Mail::Sendmail::error;
> print "OK. Log says:\n", $Mail::Sendmail::log;
>
> print "Apollo is stuck sent Email\n";
> if ($hour> 12)
> {
> print MAIL_LOG "Error Sending Email ",$hour-12,":$min\n";
> }
> else
> {
> print MAIL_LOG "Error Sending Email $hour:$min\n";
> }
> print MAIL_LOG
> "---------------------------------------------------------------------------
> ---- \n";
> close MAIL_LOG;
> exit;
>
> }
> else
> {
> if ($line eq "Sleeping for 10 second")
> {
> $count++;
> print "Count $count\n";
> print MAIL_LOG $line, "\n";
> }
> else
> {
>
> print $line, "\n";
> print "Count $count\n";
> print MAIL_LOG $line, "\n";
> }
> sleep 10;
> }
> }
> if ($hour> 12)
> {
> print MAIL_LOG "Completed ",$hour-12,":$min\n";
> }
> else
> {
> print MAIL_LOG "Completed $hour:$min\n";
> }
> print MAIL_LOG
> "---------------------------------------------------------------------------
> ---- \n";
> close MAIL_LOG;
This should work better:
#!/usr/bin/perl -w
use strict;
# the string to search for
my $search = 'Sleeping for 10 seconds';
my $count = 0;
my( $min, $hour );
open MAIL_LOG, ">> siebel_mail.log" or die "can't append to siebl_mail.log: $!";
# do this 7 times
for ( 1 .. 7 ) {
open OUTPUT, '..\\..\\srvrmgr /ser server.com /e CHK_ENT_PRD /s CHK_SBL_PRD /u
xxxxxx /p xxxxxxx /c "list tasks for server CHK_SBL_PRD component Email Manager" |'
or die "can't run srvrmgr: $!";
<OUTPUT> for 1 .. 22; # skip first 22 lines of output
# set $found to true or false
my $found = <OUTPUT> =~ /$search/;
close OUTPUT;
( $min, $hour ) = (localtime)[1,2];
$hour -= 12 if $hour > 12;
if ( $count == 4 ) {
use Mail::Sendmail; # Send and email if there are errors
%mail = ( To => '[EMAIL PROTECTED]',
From => '[EMAIL PROTECTED]',
Subject => '',
Message => 'Email Manager hung on Apollo'
);
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log;
print "Apollo is stuck sent Email\n";
print MAIL_LOG "Error Sending Email $hour:$min\n";
print MAIL_LOG
"------------------------------------------------------------------------------- \n";
close MAIL_LOG;
exit 0;
}
else {
if ( $found ) {
$count++;
}
else {
print "$search\n";
}
print "Count $count\n";
print MAIL_LOG "$search\n";
sleep 10;
}
}
print MAIL_LOG "Completed $hour:$min\n";
print MAIL_LOG
"------------------------------------------------------------------------------- \n";
close MAIL_LOG;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]