Search code examples
bashshellautosys

how to determine how much time autosys job takes to go to "success" state


Can anyone help me, I am trying to find the current status of an autosys job like below: autorep -j jobname -d -L0 | grep "RUNNING" and if it is not running, I have to force start the same job. After the same job is successfully restarted, I have to wait until the job status is SUCCESS to continue with my rest of the commands in my shell script. Please guide, many thanks for your help. Below is my code

status=`autorep -j jobname -d -L0 | grep "RUNNING"| awk '{print$1}'
echo $status
if["$status"=="RUNNING"];then
echo "The job is in RUNNING state"
else
echo "Force starting the job now !"
fsj jobname
fi

and, after the job status is success, I can continue with rest of my scripting. But the question is, how to know if I have to put sleep for 30 mins, 40 mins etc (appx job runs for 30 mins) Is there any way to automatically trigger the next command,after the job is successful...instead of using sleep. Thanks again.


Solution

  • while sleep 900; do autorep -j jobname -d -L0 |
      awk '$1~/RUNNING/{r=1} END{if(!r) system("fsj jobname")}'; done &
    

    This background loop will check the first column of your autorep output for "RUNNING" every 15 minutes, executing fsj jobname if it doesn't find a match. You might also be able to track the PID of the relevant process if you can identify it.