recov_job.pl

#!/usr/bin/perl 
#
# Script to rerun a the job in recovery
#
# 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
#==========================================================================================
 
# Print passed parameter list
$sleep_sec = int(rand(30));                          # Random default sleep value in seconds
$DQ = """;                                    # Double quote
 
$Numparms = @ARGV;                             # Get number of parameters
if ( $Numparms == 0 ) {
       &time_stamp();                                 # Get time/date stamp
       print ("$Now - No parameters passed to script - terminating in errorn");
       print ("rerunjob parameter is requiredn");
       exit 1;                                        # exit with error return code
} 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
             };
             if ( $ARGV[$count] =~ "rerunjob=" ) {
                    $_ = $ARGV[$count];                     # Get sleep parameter 
                    ($_,$rerunjob) = split(/=/, $_, 2);           # Get the seconds value
             };
       };
};
 
# Check that the rerunjob parameter has been specified
if ( ! ${rerunjob} ) {
       &time_stamp();                                  # Get time/date stamp
       print ("$Now - The rerunjob parameter is a required parameter - terminating in errorn");
       exit 2;                                        # Exit with an error return code
};
 
# Now process each of the environment variables
 
# If the TWS environment variable UNISON_JOB is present, assume we are executing under TWS
# in which case, 
 
if ( $ENV{UNISON_JOB} ) {                                                # If UNISON_JOB variable exists
       $twsdir = $ENV{TWS_TISDIR};           # Use TWS_TISDIR for UNIX
       $jobinfo = $twsdir."/bin/jobinfo";             # Build jobinfo command for UNIX
 
  $job_info = `$jobinfo rstrt_retcode 2> /dev/null`;
       $parent_rc = $job_info;
       chomp($parent_rc);
  &time_stamp();
  print ("$Now Job return code from parent job=$parent_rcn");
 
};
 
&time_stamp();
print "$Now - Sleeping for $sleep_sec secondsn" if $sleep_sec;
system("sleep $sleep_sec") if $sleep_sec; 
$cmd = "$ENV{'UNISON_DIR'}/bin/conman sbj ${rerunjob};alias=${rerunjob}_`date +%H%M%S`;into=$ENV{'UNISON_SCHED_ID'};schedid";
print "$cmd";
@rerun_job = `$cmd 2>&1`;
print "@rerun_jobn";
 
# The recovery job has to fail otherwise the dependent job will start
exit 1;