mau5
mau5

Reputation: 199

Crontab in order after completed

Is it possible to make crontab run after one's execution. I read that cron jobs start from top, but run parallel, doesn't wait one to finish. Is there any way that I can do like this? For example, let's say I have 3 cron jobs.

I want job2 to run after job1 has completed, and job3 after job2 completed.

Upvotes: 1

Views: 1366

Answers (2)

MaxV
MaxV

Reputation: 631

In case you want to use the global crontab in /etc, it's simpler. The main crontab file is /etc/crontab. It contains this type of instruction:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

so Linux uses run-parts; run-parts launch commands in alphabetical order, so just add numbers in the script like this:

  • 01_MyFisrtScrip
  • 02_MySecondScript
  • ...

and so on... Please avoid using dots or other characters that are not legal for run-parts:

  • BAD NAME = 01_myscript.sh
  • GOOD NAME = 01_myscript

Upvotes: 0

Jim Lewis
Jim Lewis

Reputation: 45045

You can have more than one command in a single crontab entry:

*/5 * * * * job1 ; job2 ; job3

Upvotes: 3

Related Questions