Since bash is horrible at date statements i had to convert my bash script
to perl....now i have a headache.. I had help to convert but now in
modifying i have messed it up..
i'm checking a returned value from a sql query and comparing it against
the date.
The two possible output types
[bluemoon@monito r]$ /usr/local/bin/sqsh -Uuser -Ppassword -S sql1 -h -i test.sql
[bluemoon@monito r]$
[bluemoon@monito r]$ /usr/local/bin/sqsh -Usql1_replicato r -Pkaiisdead -S mtsql1 -h -i test.sql
0 2003110311:53:4 2/298
i am usure as to how to include a if $SQLOutput= null then exit, else...
#!/usr/bin/perl -w
use Date::Calc qw(Delta_DHMS);
use Date::Calc qw(Delta_Days);
use POSIX qw(strftime);
require Symbol;
$SENDMAIL_EXEC = '/usr/sbin/sendmail'; # Path to sendmail(8)
$BLUEMOON_RECV_ EMAIL = 'user@domain.co m';
my $bluemoon_sende r = "bluemoon_monit or\@domain.com" ;
my @today = (strftime("%Y", localtime(time) ),strftime("%m" , localtime(time) ), strftime("%d", localtime(time) ),strftime("%H" , localtime(time) ),strftime("%M" , localtime(time) ),strftime("%S" , localtime(time) ));
my @timestamp;
my $day;
my $year;
my $month;
my $hour;
my $minutes;
my $seconds;
my $Dd;
my $Dh;
my $Dm;
my $Ds;
my $SQLOutput;
my $zero;
my $bluemoon_body;
$SQLOutput=`/usr/local/bin/sqsh -Uuser -Ppassword -S sql1 -h -i bluemoon.sql`;
if ($SQLOutput = null then exit; else < ------- not sure how to do this in
perl...
/(.)(.)(........ )(....)(..)(..) (..)(.)(..)(.)( ..)(....)/) { $zero = $2;
$year = $4; $month = $5; $day = $6; $hour = $7; $minutes = $9; $seconds = $11; }
@timestamp = ($year, $month, $day, $hour, $minutes, $seconds);
($Dd,$Dh,$Dm,$D s) = Delta_DHMS(@tim estamp,@today);
if (($Dd > 0 || $Dh > 0 || $Dm > 10) && $zero == 0 ) {
$bluemoon_body = join('',"Blue Moon Timestamp Check has
failed!\n\nThe UPLOADED Field = ",$zero,"\nTher e has not been an update
in ", $Dd," days, ", $Dh," hours and ", $Dm," minutes.\n\nPle ase restart
the interface or investigate\n\n Bluemoon TimeStamp:
",@timestamp,"\ nCurrent Timestamp: ",@today);
my $SEND_MAIL = Symbol->gensym;
open($SEND_MAIL , "|-") ||
exec($SENDMAIL_ EXEC, '-i', '-t', "-f$bluemoon_send er");
print $SEND_MAIL <<"EOF";
Date: @today
From: $bluemoon_sende r
To: $BLUEMOON_RECV_ EMAIL
Subject: Blue Moon is Down!
$bluemoon_body
EOF
close($SEND_MAI L);
}
Thanks for any help
to perl....now i have a headache.. I had help to convert but now in
modifying i have messed it up..
i'm checking a returned value from a sql query and comparing it against
the date.
The two possible output types
[bluemoon@monito r]$ /usr/local/bin/sqsh -Uuser -Ppassword -S sql1 -h -i test.sql
[bluemoon@monito r]$
[bluemoon@monito r]$ /usr/local/bin/sqsh -Usql1_replicato r -Pkaiisdead -S mtsql1 -h -i test.sql
0 2003110311:53:4 2/298
i am usure as to how to include a if $SQLOutput= null then exit, else...
#!/usr/bin/perl -w
use Date::Calc qw(Delta_DHMS);
use Date::Calc qw(Delta_Days);
use POSIX qw(strftime);
require Symbol;
$SENDMAIL_EXEC = '/usr/sbin/sendmail'; # Path to sendmail(8)
$BLUEMOON_RECV_ EMAIL = 'user@domain.co m';
my $bluemoon_sende r = "bluemoon_monit or\@domain.com" ;
my @today = (strftime("%Y", localtime(time) ),strftime("%m" , localtime(time) ), strftime("%d", localtime(time) ),strftime("%H" , localtime(time) ),strftime("%M" , localtime(time) ),strftime("%S" , localtime(time) ));
my @timestamp;
my $day;
my $year;
my $month;
my $hour;
my $minutes;
my $seconds;
my $Dd;
my $Dh;
my $Dm;
my $Ds;
my $SQLOutput;
my $zero;
my $bluemoon_body;
$SQLOutput=`/usr/local/bin/sqsh -Uuser -Ppassword -S sql1 -h -i bluemoon.sql`;
if ($SQLOutput = null then exit; else < ------- not sure how to do this in
perl...
/(.)(.)(........ )(....)(..)(..) (..)(.)(..)(.)( ..)(....)/) { $zero = $2;
$year = $4; $month = $5; $day = $6; $hour = $7; $minutes = $9; $seconds = $11; }
@timestamp = ($year, $month, $day, $hour, $minutes, $seconds);
($Dd,$Dh,$Dm,$D s) = Delta_DHMS(@tim estamp,@today);
if (($Dd > 0 || $Dh > 0 || $Dm > 10) && $zero == 0 ) {
$bluemoon_body = join('',"Blue Moon Timestamp Check has
failed!\n\nThe UPLOADED Field = ",$zero,"\nTher e has not been an update
in ", $Dd," days, ", $Dh," hours and ", $Dm," minutes.\n\nPle ase restart
the interface or investigate\n\n Bluemoon TimeStamp:
",@timestamp,"\ nCurrent Timestamp: ",@today);
my $SEND_MAIL = Symbol->gensym;
open($SEND_MAIL , "|-") ||
exec($SENDMAIL_ EXEC, '-i', '-t', "-f$bluemoon_send er");
print $SEND_MAIL <<"EOF";
Date: @today
From: $bluemoon_sende r
To: $BLUEMOON_RECV_ EMAIL
Subject: Blue Moon is Down!
$bluemoon_body
EOF
close($SEND_MAI L);
}
Thanks for any help
Comment