61

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)

3 Answers 3

96
*/2 * * * * date >>/tmp/even
1-59/2 * * * * date >>/tmp/odd
5
  • 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 7, 2011 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 7, 2011 at 21:46
  • thats what i suspected too... i ll set it manually... thank you for your help jj33 :)
    – wabbajay
    Jan 7, 2011 at 21:53
  • 11
    FYI, for the 1-59/2 syntax. if you want an explaination see stackoverflow.com/a/122499/658023 Jun 12, 2015 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, 2021 at 16:28
6
*/2 * * * * /path/to/foo
*/2 * * * * sleep 60; /path/to/bar

Is that that sleep 60 too much like a script?

1
  • 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 7, 2011 at 21:39
3

You can use

1/2 * * * * for odd minutes 
*/2 * * * * for even minutes
1
  • /tmp/crontab.ojyNoj/crontab":39: bad minute errors in crontab file, can't install. Jan 27, 2022 at 13:53

You must log in to answer this question.

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