Today is November 1st 2016 or in (unambiguous) numerals, 2016-11-01.

I have a user cron job set up like this:

# m h  dom mon dow   command
33  3   1  */2  *    /home/user/...

It is supposed to run every other month on the first of the month at 3:33am, no matter what day of week that is, but for some reason it was run today, even though 11 is not divisible by 2.

Can someone explain me this? Is my assumption of divisibility by 2 wrong?

EDIT: I forgot to mention, I am running cron version "3.0pl1-127+deb8u1" on a Debian 8.6 "Jessie" machine.

  • 2
    Possible duplicate of Why is my crontab not working, and how can I troubleshoot it? – user9517 Nov 1 '16 at 12:51
  • So you're talking about the 11th day of the 2016th month of the year 1 then. :) (The most common date order in America is month-day-year.) – chicks Nov 1 '16 at 18:25
  • @chicks check the edit history of this question, I originally used the format you mentioned ;-) – comfreak Nov 1 '16 at 20:16
  • @chicks you mean month/day/year? – user253751 Nov 2 '16 at 0:00
  • @immibis No. ... comfreak: lol – chicks Nov 2 '16 at 0:02

The / is not an arithmetic expression, instead it describes "step values" over the allowed range of values. So, since months always start with 1 instead of 0, /2 would mean "take every other value", resulting in (1, 3, 5, 7, 9, 11).

This is also decribed in the manual page, although this is not terrible clear and easy to understand:

Step values can be used in conjunction with ranges. Following a range with "<number>" specifies skips of the number’s value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2".

  • 2
    Thanks for your answer, I just realized this myself after reading the man page again and working this through in my head. I was usually only working with shorter term cron jobs where the numbers start with 0 and my assumption actually made sense in a way. – comfreak Nov 1 '16 at 12:13
  • 18
    I just mused why this question isn't asked more often and came to the same conclusion: Because few people run jobs with anything then a "*" in the month field. – Sven Nov 1 '16 at 12:15
  • One question, what would happen if the number does not divide, e.g. */5? Would it be 1,6,11,1,6... or would it be 1,6,11,4,9...? I assumed that "over the allowed range of values" means that it has no memory, but now I was not being so sure about that. – MariusSiuram Nov 2 '16 at 14:38
  • @MariusSiuram: The first variant. Again, this is not an arithmetic operation. crond just takes the list of possible values, applies the step selector once and then use these results repeatedly. – Sven Nov 2 '16 at 14:41

Today is the first day in November.

*/2 means that your cronjob will execute every other month as you say.

So next month (December) the cronjob will not be executed, but the month (January) after it will be.

The month before this month (October) the cronjob was not executed. But in September it was.

  • 1
    So you reckon that */2 in the month field is equivalent to 1-11/2, rather than 2-12/2. I'm not saying you're wrong, but can you produce any supporting documentation? – MadHatter Nov 1 '16 at 11:59
  • @MadHatter Sven did explain it well. – Orphans Nov 1 '16 at 12:54
  • 1
    I agree, and best of all he quoted authoritative sources. – MadHatter Nov 1 '16 at 13:30
  • 2
    Just pointing out, September precedes October, and not August ;-) – hjpotter92 Nov 2 '16 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.