3

I have 6 scripts that each take about 20 minutes to run, I want to schedule cron to run the first 3 at 00, 20, and 40 on the odd hours and the second 3 at the same intervals on the even hours. How can I tell cron to do this?

is it something like this:

0 2,4,6,8,10,12,14,16,18,20,22,24 * * * root Script1
20 2,4,6,8,10,12,14,16,18,20,22,24 * * * root Script2
40 2,4,6,8,10,12,14,16,18,20,22,24 * * * root Script3
0 1,3,5,7,9,11,13,17,19,21,23 * * * root Script4
20 1,3,5,7,9,11,13,17,19,21,23 * * * root Script5
40 1,3,5,7,9,11,13,17,19,21,23 * * * root Script6
1
  • 1
    Yup. Like that.
    – Cory J
    May 21, 2010 at 1:43

2 Answers 2

6
0  0-23/2 * * * Script1
20 0-23/2 * * * Script2
40 0-23/2 * * * Script3
0  1-23/2 * * * Script4
20 1-23/2 * * * Script5
40 1-23/2 * * * Script6

Or switch the 0 hour and the 1 hour as desired.

2

Besides Ignacio's answer: if your scripts take "about 20 minutes" each and you want to avoid two of them running simultaneously, you might prefer to write a miniscript that just run the six scripts in sequence, and put that script in your crontab, to run every two hours. This is more simple, and as long as the full sequence of 6 scripts run in less than two hours, you are fine.

1
  • In this case, protections could also be added to the script to prevent a second instance from running while the first has not yet completed. And... if you did that, you could crontab it as often as you like. May 21, 2010 at 3:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .