82

In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value.

Is there a way to specify every odd value? (Would something like "1+*/2" work?)

levik
  • 114,835
  • 27
  • 73
  • 90

6 Answers6

106

Depending on your version of cron, you should be able to do (for hours, say):

   1-23/2

Going by the EXTENSIONS section in the crontab(5) manpage:

   Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".

For a more portable solution, I suspect you just have to use the simple list:

   1,3,5,7,9,11,13,15,17,19,21,23

But it might be easier to wrap your command in a shell script that will immediately exit if it's not called in an odd minute.

zigdon
  • 14,573
  • 6
  • 35
  • 54
84

Every odd minute would be:

1-59/2 * * * * 

Every even minute would be:

0-58/2 * * * * 
grigb
  • 1,151
  • 8
  • 14
5

I realize this is almost 10 years old, but I was having trouble getting 1-23/2 for an every two hour, odd hour job.

For all you users where, exact odd hour precision is not needed. I did the following which suited my teams needs.

59 */2 * * *

Execute the job every two hours, at the 59th Minute.

pbjolsby
  • 83
  • 1
  • 6
4

Try

1-23/2

From your question, I'm assuming Vixie Cron. I doubt this will work with any other cron.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
3

As I read the manual "1-23/2" (for hours) would do the trick.

erlando
  • 6,736
  • 4
  • 24
  • 29
0

Works on Cronie Even with 5 minutes interval e.g.

3-58/5 * * * * /home/test/bin/do_some_thing_every_five_minute
j0k
  • 22,600
  • 28
  • 79
  • 90