60

I have 2 cron jobs, i want one of them to run every odd minute (1,3,5,7,9,11....57,59) and i want the other one to run every even minute (0,2,4,6,8,10,12...58)

how can i do it in an easy way? (no scripting - just cron job rules)

wabbajay
  • 609
  • 1
  • 5
  • 3

3 Answers3

95
*/2 * * * * date >>/tmp/even
1-59/2 * * * * date >>/tmp/odd
jj33
  • 11,178
  • 1
  • 37
  • 50
  • whoops! i bet you supplied the correct syntax for the "1-59/2" part... can i ask why when i enter this in cpanel it doesnt work? It says "Cron field not formatted correctly..." – wabbajay Jan 07 '11 at 21:43
  • I don't use cpanel, but I'm going to go out on a limb and suggest that the filter they have placed between you and the actual crontab doesn't see it as valid. It really is though, I typed that exactly into my crontab on a CentOS5 server and got the even minutes in in /tmp/even and odd minutes in /tmp/odd. Sorry cpanel's filtering it... – jj33 Jan 07 '11 at 21:46
  • thats what i suspected too... i ll set it manually... thank you for your help jj33 :) – wabbajay Jan 07 '11 at 21:53
  • 11
    FYI, for the 1-59/2 syntax. if you want an explaination see http://stackoverflow.com/a/122499/658023 – General Redneck Jun 12 '15 at 21:19
  • This worked fantastic, thank you! I'm setting up a dedicated fan controller I wanted to run one minute at a time (apply power to USB, remove power to USB) and this does exactly what was needed. – Matthew Oct 19 '21 at 16:28
6
*/2 * * * * /path/to/foo
*/2 * * * * sleep 60; /path/to/bar

Is that that sleep 60 too much like a script?

Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
  • 2
    yes its more like a script and for sure it is not "just cron job rules". thank you for your time anyway ;) – wabbajay Jan 07 '11 at 21:39
3

You can use

1/2 * * * * for odd minutes 
*/2 * * * * for even minutes