Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a total of 9 cron jobs that I need to each to run once with 15 minute intervals in a 2:15 hour time window. So for example starting at midnight:

First Cycle

0:00 - Cron 1
0:15 - Cron 2
0:30 - Cron 3
0:45 - Cron 4
1:00 - Cron 5
1:15 - Cron 6
1:30 - Cron 7
1:45 - Cron 8
2:00 - Cron 9

Second Cycle

2:15 - Cron 1
2:30 - Cron 2
2:45 - Cron 3
3:00 - Cron 4
3:15 - Cron 5
3:30 - Cron 6
3:45 - Cron 7
4:00 - Cron 8
4:15 - Cron 9

Third Cycle

4:30 - Cron 1
4:45 - Cron 2
5:00 - Cron 3
5:15 - Cron 4
5:30 - Cron 5
5:45 - Cron 6
6:00 - Cron 7
6:15 - Cron 8
6:30 - Cron 9

and so on and so forth. How would I set up my intervals?

share|improve this question

migrated from stackoverflow.com Feb 10 '12 at 23:29

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 1 down vote accepted

Cron jobs are time-based, and good with regular intervals. With an unregular interval (here: 135mins), I guess you can only define the cron like this:

0  0 * * *  /your/cron1
15 0 * * *  /your/cron2
30 0 * * *  /your/cron3
45 0 * * *  /your/cron4
...
0  6 * * *  /your/cron7
15 6 * * *  /your/cron8
30 6 * * *  /your/cron9

...and so on.

An alternative would be something like described in this SO post.

share|improve this answer

Here's an alternative to having lots of cron schedules which, depending on the use case, might prove more flexible.

I have some tasks that need to run periodically except during certain periods through the day. This is achieved by having a regular cron schedule to run the task as preset intervals, say every 5 or 10 minutes. Then, for every time period where I don't want the task to run there are two schedules, one at the start and one at the end of that time period. The first one creates a flag file and the second deletes it. The task to be run checks for the presence of that flag file and simply quits if it exists. Obviously the revers could be applied if that is more appropriate.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.