ksh: How to tell when a job run in the background has completed?

From: egold@fsa.com
Date: Tue Mar 15 2005 - 18:11:19 EST


Hi Gurus,
sorry if this is off topic.

in ksh, Is there any way to tell when each job run in the background have
completed if you are running 9 jobs at a time in the background?

I am writing 3 ksh scripts to run about 300 jobs but im stuck on one part
of the code.

basically i have the 3 main scripts which each readsits own list of
commands to run from a command_list file.
because of license issues I can only run 9 jobs at a time, so i am trying
to always have 9 jobs running at a time, no less or more than 9. If i run
more than 9 the jobs fails and moves on to the next one which will keep
failing until a license is available, and i only have 9 licenses.

The jobs all take different amount of times to complete.
I was trying to setup a loop to run the commands in the background and
count each job as it starts and finishes, but i realised i cant tell when
they finish if i run them in the background.

Is there any way to tell when jobs run in the background have completed?
That would solve my issue.

Here is the code I have so far, this is a sample of one the main jobs, i
have 3 sets of this main job and all 3 main jobs together cannot run more
than 9 jobs total at a time. If all 3 are running at the same time i would
like them to each run 3 at a time, but if 2 of the main jobs finish, i
would like the remaining one to start running 9 at a time so they each will
finish as fast as possible.

RUNREPORTS1 ()
{
OLDIFS=$IFS
IFS="
"
REPORTFILE=`cat /tmp/report_list`
for X in $REPORTFILE
do
ksh ". /etc/profile; $X &"
# This is the part of the code where I need help figuring out when a job in
the background is done, so i can count the # im running.
done
IFS=$OLDIFS
}

Here is a sample of the report_list1 file:

/data/bin/reporter -m MYCO -D $DATE -c"YTD:SDSL" -s 01/01/1997
/data/bin/reporter -m MYCO902 -D $DATE -c"YTD:JFDKL" -s 01/01/1997
/data/bin/reporter -m MYCO3 -D $DATE -c"YTD:WEL" -s 01/01/1997
/data/bin/reporternew -m MYCO884 -D $DATE -c"YTD:JYUKL" -s 01/01/1997
/data/bin/reporternew -m MYCO5 -D $DATE -c"YTD:JDFKL" -s 01/01/1997
/data/bin/reporterX -m MYCO6 -D $DATE -c"YTD:JZXKL" -s 01/01/1997
/data/bin/reporterX -m MYCO234 -D $DATE -c"YTD:JBVKL" -s 01/01/1997
/data/bin/reporternew -m MYCO8 -D $DATE -c"YTD:JKXCL" -s 01/01/1997
/data/bin/reporter -m MYCO65 -D $DATE -c"YTD:JKLKL" -s 01/01/1997
/data/bin/reporter -m MYCO234 -D $DATE -c"YTD:JOOKL" -s 01/01/1997
.
.
.
.
this goes on for over 300 unique commands

thank you in advance!

____________________________________
This e-mail message is for the sole use of the intended recipient(s) and
may contain proprietary, confidential and/or privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited. If you
are not the intended recipient (or an employee or agent responsible to
deliver it to the intended recipient), you may not copy or deliver this
message to anyone. In such case, you should destroy this message and kindly
notify the sender by reply e-mail.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:30:21 EDT