Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If anyone it's like me and work even once with IBM Mainframe batch jobs, then it's possible that you know CONTROL-M, that is a tool to schedule jobs not only in a date and time fashion but also in terms of conditionals base on success or failures of other jobs

So i wonder if in a linux machine if this possible with the cron server. The only way I know if that a cron job must run at certain date and time, now I want to run in a chain of other cron jobs. Say so that when one finish triggers the other one to start and so.

It's there a way to accomplish this?

Best, Demian

share|improve this question

The standard approach to running one command if another fails is to check the first command's exit status for anything other than success and run if so.

Here's one recently seen hacktastic example:

### Start SSH if it stops. 
*/8 * * * * /usr/lib/nagios/plugins/check_ssh -p 22 > /dev/null || /etc/init.d/sshd restart

The above will only run the "/etc/init.d/sshd restart" command if the initial command fails. That's exactly what you're looking for. I imagine it's only on that mainframe because it duplicates simple conditional statements that exist in just about every shell.

If you have a whole bunch of "jobs" that should be run ONLY if the first fails...then just place all those jobs in a shell script and the initial command in the cron:

# Run my cool script if "somecommand" fails.
*/8 * * * * /usr/bin/somecommand || /home/foo/bin/

For bash the && and || built-ins will do.

share|improve this answer
Good answer, I'm very impressive about your knowledge! – denica001 Mar 2 '10 at 6:35
Thanks, good question. You can mark this answer as correct if you feel this properly answers your question. ;) – CarpeNoctem Mar 2 '10 at 7:26

Or you could install a scheduling server: "job scheduler" is a good GPL project on Sourceforge

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.