1831320 Members
3042 Online
110023 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
David Peacock
Frequent Advisor

shell script

One of my users wants to have 2 cron jobs
running at the same time. She wants to
start a third cron job after both are complete.

How can I make it so the third job will begin
after there is a confirmation that the first
two jobs have completed.

Thank you
veni, vidi, vmstat
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: shell script

I can think of 3 methods instantly:

I. Start all 3 jobs simultaneously but have the third job loop with a sleep until two files have been written (by jobs 1 & 2). Job 3 then removes these files and starts processing.

2) 1 cronjob that does this:

job1 &
job2 &
wait
start job 3 processing.

The wait command will wait fore all background processes to complete.

C) You could have job2 issue an at command:
e.g. at /usr/local/bin/myfile.sh at now + 5 minutes.


My preference is 2.

If it ain't broke, I can fix that.
Hai Nguyen_1
Honored Contributor

Re: shell script

I'd like A. Clay Stephenson's second method. It is reliable and does simplify the job controlling (all the three jobs are launched from one cron script.)

Hai
harry d brown jr
Honored Contributor

Re: shell script


Just create a simple script that is started from cron that starts the first two "jobs" then checks the return status of each before launching the third.

live free or die
harry
Live Free or Die