Romulus
Romulus

Reputation: 1684

Crontab every other hour and then the other hours

I have crontab scripts that run every other hour

2  */2  *   *   * cd /home/myuser/scripts && ./script.sh
4  */2  *   *   * cd /home/myuser/scripts && ./script2.sh
6  */2  *   *   * cd /home/myuser/scripts && ./script3.sh
8  */2  *   *   * cd /home/myuser/scripts && ./script4.sh
...

I would like to add more scripts that run on every other hour, but not the hours that the above scripts run on. So that the above scripts all run on their respective hour/minutes lets say on 1PM, 3PM ... and my new scripts run on 2PM, 4PM ...

Upvotes: 2

Views: 1135

Answers (1)

Erin
Erin

Reputation: 386

I think you mean you want the new scripts to run on every other odd hour. If that's the case:

2  1-23/2  *   *   * cd /home/myuser/scripts && ./script5.sh
4  1-23/2  *   *   * cd /home/myuser/scripts && ./script6.sh
6  1-23/2  *   *   * cd /home/myuser/scripts && ./script7.sh
8  1-23/2  *   *   * cd /home/myuser/scripts && ./script8.sh
...

So script5.sh will run exactly one hour before/after script.sh, and script6.sh will run exactly one hour before/after script2.sh.

A reference: http://www.poweradded.net/2011/04/how-to-run-cron-jobs-on-evenodd-days.html

And if I'm interpreting your question correctly, I think it's been asked before: Specifying "all odd values" in crontab?

Upvotes: 2

Related Questions