Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

cron - Specifying "all odd values" in crontab?

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?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...