Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying "all odd values" in crontab?

Tags:

cron

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

like image 563
levik Avatar asked Sep 23 '08 17:09

levik


People also ask

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

What is cron expression 0 * * * *?

Meaning of cron expression 0 * * * * *? I think it means the scheduler is expected to run every seconds.

How do I list all crons?

You can find them in /var/spool/cron/crontabs. The tables contain the cron jobs for all users, except the root user. The root user can use the crontab for the whole system. In RedHat-based systems, this file is located at /etc/cron.

Can I use tilde in crontab?

1 Answer. Show activity on this post. You should try using $HOME rather than ~ as tilde expansion is not reliable in a cron job.


2 Answers

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.

like image 63
zigdon Avatar answered Oct 12 '22 22:10

zigdon


Every odd minute would be:

1-59/2 * * * *  

Every even minute would be:

0-58/2 * * * *  
like image 40
grigb Avatar answered Oct 12 '22 23:10

grigb