job_one.pl
#!/usr/bin/perl
#
# This script is run from the job ORB_JOB1 as part of the tip
# TWS recover and rerun job until it succeeds.
#
# 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");
$TestDir = "/images/TWS/TWS-Testing/Files"; # Default directory for testing
#------------------------------------------------------------------------------------------
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 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
};
};
$TestDir = $ARGV[0]; # Set path to test files
#print ("TestDir set to $TestDirn");
};
# Now process each of the environment variables
&time_stamp();
print ("$Now - Environment variables follow...nn");
# If the TWS environment variable UNISON_JOB is present, assume we are executing under TWS
# in which case,
# if the file $TestDir/Files/jobname.test exists, delete it and exit with RC=1
# if the file doesn't exist, create it and exit wth RC=0
# This allows TWS to schedule the job and it will alternatively fail and succeed on each run
if ( $ENV{UNISON_JOB} ) { # If UNISON_JOB variable exists
$twsdir = $ENV{TWS_TISDIR}; # Use TWS_TISDIR for UNIX/Linux
$jobinfo = $twsdir."/bin/jobinfo"; # Build jobinfo command for UNIX/Linux
$DevNull = "/dev/null"; # Null device UNIX/Linux
# Print information about the job from jobinfo command
$job_info = `$jobinfo re_job 2> $DevNull`;
&time_stamp();
print ("$Now Job is a RERUN job=$job_info");
# Now sleep for a little while
print ("n$Now - Sleeping for $sleep_sec seconds....n");
system("sleep $sleep_sec"); # Sleep for 1 minutes so we can see job in TWS!
($Jobstream, $Jobname) = split(/./, $ENV{UNISON_JOB}, 2); # Jobname after the "."
&time_stamp(); # Get time/date stamp
print ("$Now - Executing under TWS Jobstream $Jobstream Job $Jobnamen");
$Filename = "$TestDir" . "/" . "job1.test"; # Build filename
if ( -f $Filename ) { # File exists
unlink($Filename); # Delete file
&time_stamp();
print ("$Now - File $Filename exists and has been deleted!n");
exit 0;
} else {
print ("$Now - File $Filename does not exist!n");
exit 1;
};
};
exit 0;
Hits: 3