rerun_job.pl

#!/usr/bin/perl
#
# Script to rerun failing job in the current job stream
#
# Day and Month arrays used by time_stamp subroutine
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
 
#------------------------------------------------------------------------------------------
sub time_stamp {                                        # Get date/time in printable format
#------------------------------------------------------------------------------------------
        local ($sec,$min,$hour,$day,$month,$year,$dayofweek,$dayofyear,$daylightsaving);
 
        ($sec,$min,$hour,$day,$month,$year,$dayofweek,$dayofyear,$daylightsaving) = localtime(time);
 
        $MTH = substr($months[$month],0,3);             # Set month abbreviation
        $DAY = substr($days[$dayofweek],0,3);           # Set day abbreviation
 
        if ( $year <= 2000) {
                $YEAR = $year + 1900;                   # Add 1900 if year is less than 2000!
        } else {
                $YEAR = $year;                          # otherwise assume it's okay
        };
        if ( $day < 10) {
                $day = "0".$day                         # Add leading zero
        };
        if ( $hour < 10) {
                $hour = "0".$hour                       # Add leading zero
        };
        if ( $min < 10) {
                $min = "0".$min                         # Add leading zero
        };
        if ( $sec < 10) {
                $sec = "0".$sec                         # Add leading zero
        };
        $Now = $day.$MTH.$YEAR."-".$hour.":".$min.":".$sec      # Return timestamp in $Now variable
};
 
#==========================================================================================
# Main starts here
#==========================================================================================
 
$Numparms = @ARGV;                             # Get number of parameters
if ( $Numparms == 0 ) {
       &time_stamp();                                 # Get time/date stamp
       print ("$Now - No parameters passed to scriptn");
} else {
       &time_stamp();                                 # Get time/date stamp
       print ("$Now - Parameters passed to script as follows:-n");
       for ($count = 0; $count < @ARGV; $count++) {   # Print each parameter value
             print ("ttt$ARGV[$count]:t$ARGV[$count]n");  # Print parameter
             if ( $ARGV[$count] =~ "sleep=" ) {
                    $_ = $ARGV[$count];                     # Get sleep parameter 
                    ($_,$sleep_sec) = split(/=/, $_, 2);          # Get the seconds value
             };
       };
};
 
# Get the jobs in this job stream
@list_js = `$ENV{'UNISON_DIR'}/bin/conman sj $ENV{'UNISON_SCHED_ID'};schedid`;
 
# Find the failing job
$count = 0;
foreach $i (@list_js) {
       $count++;
       
       last if $i =~ /recovery/;
 
       if ( $i =~ /ABEND/ ) {
             $abend_line = $i;
             ($rest, $FailingJob, $rest2) = split(/s+/, $abend_line);
       }
}
 
print "Sleeping for $sleep_sec secondsn" if $sleep_sec;
system("sleep $sleep_sec") if $sleep_sec;       
 
# Rerun the failing job
$cmd = "$ENV{'UNISON_DIR'}/bin/conman rr $ENV{'UNISON_SCHED_ID'}.${FailingJob};schedid";
print "$cmd";
@rerun_job = `$cmd 2>&1`;
print "@rerun_jobn";
 
# The rerun job has to exit successfully otherwise the job stream will not succeed after all
# jobs have finished successfully
exit 0;