automatically check job status

I have written a BASH script to autmatically start several jobs. I want to add additional function to the script so it would check these jobs from time to time (the jobs could take as short as 2 hours or as long as 1 day to finish). If a job is done, check the log file and output the error into a new file.

Could anyone give me some help here? I am a noobs to scripting. Thanks a lot!

You can make sure of crontab and a script like this

#!/bin/bash
#script name : monitor

#the actual job names to be monitored
jobs="job1 job2"
log_path="/tmp"
for j in $jobs
do
  pgrep $j >/dev/null
  if [ $? -ne 0 ]
  then
    grep -i "Error" $log_path/$j >> /tmp/error.log
  fi
done

And crontab entry. The monitor script will run every 10 minutes. For more info man crontab

*/10 * * * * /tmp/test/monitor

Assuming all the log will be at a common path say /tmp/<job name>.log

--ahamed

Thanks ahamed! How can i use the script to save the job names for those jobs i already submit? I guess I should do sth when I submit each of them in my loop, but don't know what command should do it.

---------- Post updated at 04:32 PM ---------- Previous update was at 01:53 PM ----------

My thought was to keep a list of pid, update this list once a while, e.g. every 5 minutes. once the list is empty, generate the error file from the logs.

suppose one of the pid in the list is 11335:

 
testa=`ps -u myid | grep " 11335 "`
 
 
if [$testa !="" ]
then
echo "find ksh"
else
echo "not find ksh"
fi

Apparently the comparison is not correct ([$testa !="" ]). I don't know in this situation, how could I compare the return with empty (string)?

Yes, you can make use of pid also.

if [ ! -z "$testa" ]
then
   echo "find ksh"
else
   echo "not find ksh"
fi

PS : Use code tags!

--ahamed