Setting "all odd values" in crontab?

In crontab, I can use an asterisk to indicate each value, or "* / 2" to indicate any even value.

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

+61
cron crontab
Sep 23 '08 at 17:32
source share
6 answers

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

1-23/2 

Go to the Extensions section of the crontab (5) man page:

  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 need to use a simple list:

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

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

+89
Sep 23 '08 at 17:35
source share

Every odd minute would be the following:

 1-59/2 * * * * 

Every even minute:

 0-58/2 * * * * 
+57
Feb 21 2018-11-21 at
source share

Try

 1-23/2 

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

+2
Sep 23 '08 at 17:34
source share

As I read the “1-23 / 2” manual (for several hours), this would do the trick.

+2
Sep 23 '08 at 17:35
source share

Powered by Cronie Even with an interval of 5 minutes, for example

 3-58/5 * * * * /home/test/bin/do_some_thing_every_five_minute 
0
May 03 '12 at 8:07 a.m.
source share

I understand that this is almost 10 years, but I had problems getting 1-23 / 2 for every two hours of work at an inopportune hour.

For all users where accurate odd hour accuracy is not required. I did the following that fit the needs of my team.

 59 */2 * * * 

Complete the task every two hours at the 59th minute.

0
Jul 01 '19 at 16:41
source share



All Articles