Return status of all previous runs

hi, I set the crontab to execute script A every 5 minutes from 9:00 am to 4:00 pm everyday, now at 12:00am I want to run another script if and only if all the previous runs of script A return OK, can anyone tell me how it could be done? thank you very very much!

Set your script up to write to a tmp file a success or failure. Then take your new script and grep the file for failure. If failure exists then your cron script exits and notifies you. If no failure is found then you proceed and have that script notifiy you as well.

-X

You could split your cron line into three this way:

00,05,10,15,20,25,30,35,40,45,50,55 4-11,13-21 * * * script1.sh
00 12 * * * script1.sh && script2.sh
05,10,15,20,25,30,35,40,45,50,55 12 * * * script1.sh

At 12:00 script2.sh will only run if script1.sh finished with exit status of 0.
So you won't need a temp file.
Well, I think this should work, but I'm not sure :slight_smile:

thank you guys, but could grial explains how your method works with a little more detail? I have pretty new with these stuff, thanks!

Of course :slight_smile:
Well, of the three crontab lines above, the second is the interesting one for you:

00 12 * * * script1.sh && script2.sh

You may consider it as a boolean expression, meaning that
script2.sh will run if, and only if, script1.sh finished successfully (exit 0).
This will happen at twelve o'clock.

The first line says that script1.sh will run from 4 to 11 and from 13 to 21 every 5 minutes. The last line says that script1.sh will run every 5 minues from 12.
Regards.