understanding cron and step */3

I understand that stepping in cron (*/2) means "every two [minutes|days|hours] equivalent to 0,2,4,6…

but what would happen if I did (1-11/2) Would this do 2,4,6… or 1,3,5…?

I have two computers in a network, and I want them to alternate days that they perform a cron job (to save bandwidth and headaches). I want the first one to do work on day-of-the-month 1,3,5,… and the other to do day-of-the-month 2,4,6

1 1 1-31/2 * * command
1 1 0-30/2 * * command

is that right?

Just write




to be sure. You only have to do it once, haven’t you?

BTW I alow you to cut and paste the above to make it easier rotfl!

The man page for crontab (5) isn’t totally clear on this but it seems to suggest that /2 means an even number, and the range merely restricts the even values are are accepted, it doesn’t change the start of the sequence. Just do it like hcw says, or run the script every day, and inside the script use an arithmetic expression involving % 2 on the day of month to select the machine.

I have just confirmed that it is indeed correct when I suggested in my first post

1-59/2 * * * * date

Gives mail containing “Wed Mar 25 17:55:01 EST 2009” every other minute (odd minutes)

0-58/2 * * * * date

Gives mail containing “wed Mar 25 17:56:01 EST 2009” every other minute (even minutes)

Actually it turns out on more careful reading that this behaviour is already documented, if you look further down the man page of crontab (5), it says:

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

However it is specified in the EXTENSIONS section, meaning that this behaviour is not required by POSIX but is implemented by Vixie cron. So beware if you try to run this cron spec on other Unixes.

And then we are back at my conservative behaviour. Write something so that it possibly runs on all Unixes/Linuxes. :wink: