Mabuhay

Hello world! This is it. I've always wanted to blog. I don't want no fame but just to let myself heard. No! Just to express myself. So, I don't really care if someone believes in what I'm going to write here nor if ever someone gets interested reading it. My blogs may be a novel-like, a one-liner, it doesn't matter. Still, I'm willing to listen to your views, as long as it justifies mine... Well, enjoy your stay, and I hope you'll learn something new because I just did and sharing it with you.. Welcome!

Wednesday, January 28, 2009

Scripting 101: Monitor Long-running Autosys Jobs

HELLo World! It's been sometime since I made a "working" script. The last time I remember I created is about 2 years ago [I guess]. I lost interest in programming for a while for some work-related reason and just had this renewed interest a few weeks back. Without much a-doo, here it is: [Sorry 'bout the format, I'm not in the mood to edit it - for now]


#!/bin/bash
### Calls some environment settings to use Autosys

. /sbcimp/shared/config/CA/Autosys/v4.0/prod/autouser/shellPLN


### Declaration of VARIABLES

declare -i SKIPTIME
declare -i NOMIN
declare -i NOSEC

ERRLOG=/home/$USER/Err.log

E_NOTFOUND=66


### Prompts the user for INPUTS

read -p "Enter the Job Name: " JOBNAME

read -p "Enter the time interval between display (in seconds): " SKIPTIME


### Check to make sure "interval" is integer; don't know what else to
do...
if [ $SKIPTIME -le "0" ]
then
echo "Make sure time interval is greater than zero or a number."
exit 1
fi

### This part acts as catch for INVALID Jobs
CHKINVJOB=`autorep -J $JOBNAME`
echo $CHKINVJOB > $ERRLOG

if [ ! -f $ERRLOG ]
then
echo "Error log file does not exist! Check write permissions on the directory."
exit $E_NOTFOUND
exit 1
fi

more $ERRLOG | grep Invalid
if [ $? == "0" ]
then
more $ERRLOG
echo "--- Clearing $ERRLOG ... ---"
cat /dev/null > $ERRLOG
exit 1
fi

### This part checks for the status of the Job
while true
do
autorep -J $JOBNAME | sed -n '5p' | grep -w SU > /dev/null
if [ $? == "0" ]
then
clear
echo "---- Feed Status ----"
echo
echo "***** Job ended SU-ccessfully! *****"
autorep -J $JOBNAME
echo "---- End of Status ----"
exit 0
elif [ $? == "1" ]
then
autorep -J $JOBNAME | sed -n '5p' | egrep -w "ST|AC|RU" > /dev/null
if [ $? == "0" ]
then
if [ "$SKIPTIME" -gt "60" ]
then
NOMIN=`expr $SKIPTIME / 60`
NOSEC=`expr $SKIPTIME % 60`
clear
echo "---- Feed Status ----"
echo "It is still processing... will report in approx. $NOMIN minutes and $NOSEC seconds."
sleep $SKIPTIME
autorep -J $JOBNAME | sed -n '5p'
echo "---- End of Status ----"
else
clear
echo "---- Feed Status ----"
echo "It is still processing... will report in approx. $SKIPTIME seconds."
sleep $SKIPTIME
autorep -J $JOBNAME | sed -n '5p'
echo "---- End of Status ----"
fi
else
clear
echo "---- Feed Status ----"
echo "Check for any ERROR."
autorep -J $JOBNAME
echo "---- End of Status ----"
exit 1
fi
fi
done

exit 0

No comments:

Post a Comment

World Clock