I have a script which compares the returned value of a script 45 seconds apart. Depending
on whether the two returned values are the same the script either exits or emails a notification.
I had to change the way the value is generated. Previously i was using sqsh but since we moved to sql 2000 i had to find another way. So, i am using DBI::Sybase.
The main script runs and as part of it runs the first script, the first script runs a query and gets a timestamp,
this populates the variable in the main.
--------------------------
----------
----------
----------
----------
----------
----------
-
#!/usr/bin/perl -w
BEGIN { $ENV{SYBASE} = '/usr/local/freetds'; }
#
# test the db2 dbi driver
use warnings;
use strict;
use DBI ;
my $dbh = DBI-> connect( 'dbi:Sybase:server=sql1','
user','pas
sword',{ RaiseError => 1, AutoCommit => 0} ) || die "Database connection not made: $DBI::errstr\n";
my $sql= "select TIMESTMP from UPLOAD where TIMESTMP = (select MAX (TIMESTMP) from UPLOAD)select UPLOADED from UPLOAD where UPLOADED <1;";
my $sth = $dbh->prepare ($sql)|| die "Prepare failed: $DBI::errstr\n";
$sth->execute() || die "Couldn't execute query:$DBI::errstr\n";
while(my @array = $sth->fetchrow())
{
print "@array\n";
}
$sth->finish();
$dbh->disconnect() || die "Failed to disconnect\n";
--------------------------
----------
----------
----------
----------
----------
----------
-
an example of the output provided by the query script (above) is
[bluemoon@box scripts]$ perl query.pl
2004060314:17:24/377
the idea is to get two values 45sec apart - these should always be the same. If they differ it means a process is down that we rely on.
BUT when i run the script i get back an error;
the error is;
Use of uninitialized value in subroutine entry at bluemoonchk.pl line 50.
Date::Calc::Delta_DHMS(): not a valid date at bluemoonchk.pl line 50.
Could be simple, could be hard - 500pts up for grabs.
thanks for any help.
here is the second script
--------------------------
----------
----------
----------
----------
----------
----------
-
#!/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 = 'xscousr@domain.com';
my $bluemoon_sender = "bluemoon_monitor\@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 $SQLOutput1;
my $SQLOutput2;
my $zero;
my $bluemoon_body;
$SQLOutput1=`perl /home/bluemoon/scripts/que
ry.pl`;
exit unless $SQLOutput1;
sleep (45);
$SQLOutput2=`perl /home/bluemoon/scripts/que
ry.pl`;
exit unless $SQLOutput2;
if ($SQLOutput1 ne $SQLOutput2) {
exit;
} else {
if ($SQLOutput1 =~ /(.)(.)(........)(....)(..
)(..)(..)(
.)(..)(.)(
..)(....)/
) { $zero = $2; $year = $4; $month = $5; $day = $6; $hour = $7; $minutes = $9; $seconds = $11; }
@timestamp = ($year, $month, $day, $hour, $minutes, $seconds);
########### THIS IS LINE 50 FROM THE RETURNED ERROR ###################
($Dd,$Dh,$Dm,$Ds) = Delta_DHMS(@timestamp,@tod
ay);
##########################
##########
##########
##########
##
if (($Dd > 0 || $Dh > 0 || $Dm > 5 ) && $zero == 0 ) {
$bluemoon_body = join('',"Blue Moon Timestamp Check has failed!\n\nThe UPLOADED Field = ",$zero,"\nThere has not been an update in ", $Dd," days, ", $Dh," hours and ", $Dm," minutes.\n\nPlease restart the interface or investigate\n\nBluemoon TimeStamp: ",@timestamp,"\nCurrent Timestamp: ",@today);
my $SEND_MAIL = Symbol->gensym;
open($SEND_MAIL, "|-") ||
exec($SENDMAIL_EXEC, '-i', '-t', "-f$bluemoon_sender");
print $SEND_MAIL <<"EOF";
Date: @today
From: $bluemoon_sender
To: $BLUEMOON_RECV_EMAIL
Subject: Blue Moon is Down!
$bluemoon_body
EOF
close($SEND_MAIL);
}
}
--------------------------
----------
----------
----------
----------
----------
----------
-