[TriLUG] Why does my "every second month" cron job run on odd-numbered months?

Aaron Joyner via TriLUG trilug at trilug.org
Thu Aug 28 13:07:09 EDT 2025


Paul's right.  Assuming you're using vixie cron (or a derivative, or most
any implementation?), the cron field for month is one-ordered, and so
unpacking the wildcard in your step command works morally like this:
0 3 1 *1,2,3,4,5,6,7,8,9,10,11,12*/2 * /do/a/thing.sh

Walking that schedule takes every other step, starting with the 1.  You can
find the source and the constants defining the range here:
https://github.com/vixie/cron/blob/9cc8ab1087bb9ab861dd5595c41200683c9f6712/macros.h#L117-L119

With some light browsing, you can also see how they mesh between that
format and the time_t syntax which uses zero-ordered month in this line:
https://github.com/vixie/cron/blob/master/cron.c#L292

... and that this is where the wildcard gets expanded, into the range from
low to high:
https://github.com/vixie/cron/blob/master/entry.c#L492-L499

This doesn't align with the Debian man page for Vixie cron which
weirdly says it accepts 0-12:
https://manpages.debian.org/unstable/cron/crontab.5.en.html
month 0-12 (or names, see below)

... although later is correctly and more clearly says:

month (1 - 12) OR jan,feb,mar,apr ...

I didn't take the time to actually go test what happens, but my advice
would be to be that if you want to run on the even months, just be more
explicit about what you want, like this:
0 3 1 2,4,6,8,10,12 * /do/a/thing.sh

This version is probably even more readable, and more helpful to future-you
in 5 years when you've forgotten this conversation and go poking around in
/etc/crontab again:
0 3 1 Feb,Apr,Jun,Aug,Oct,Dec * /do/a/thing.sh

Best wishes,
Aaron S. Joyner

On Thu, Aug 28, 2025 at 12:09 PM Paul Bennett via TriLUG <trilug at trilug.org>
wrote:

> Months are numbered starting from 1, right? I think we expect "every 2" to
> be "0, 2, 4, 6, ..." but if there is no zero it does feel right to see "1,
> 3, 5, 7, ..." as the next best thing. Maybe?
>
> On Thu, Aug 28, 2025, 11:52 Brian via TriLUG <trilug at trilug.org> wrote:
>
> > Hi Gang,
> >
> > I have a crontab entry with the following schedule spec:
> > 0 3 1 */2 * /do/a/thing.sh
> >
> > According to crontab.guru, that means “At 03:00 on day-of-month 1 in
> > every 2nd month" which is what I intend.
> >
> > However, also according to crontab.guru, the upcoming schedule is:
> >
> > next at 2025-09-01 03:00:00
> > then at 2025-11-01 03:00:00
> > then at 2026-01-01 03:00:00
> > then at 2026-03-01 03:00:00
> > then at 2026-05-01 03:00:00
> >
> > Odd-numbered months.  Why?  I would interpret "every second month" to
> > mean the even-numbered months.  Is crontab.guru wrong?  Am I wrong?
> >
> > Also, is there a command-line tool to answer "when will my cron tasks
> > run next"?
> >
> > Thanks,
> > -Brian
> > --
> > This message was sent to: Paul Bennett <paul.w.bennett at gmail.com>
> > To unsubscribe, send a blank message to trilug-leave at trilug.org from
> that
> > address.
> > TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> > Unsubscribe or edit options on the web  :
> > https://www.trilug.org/mailman/options/trilug/paul.w.bennett%40gmail.com
> > Welcome to TriLUG: https://trilug.org/welcome
> --
> This message was sent to: Aaron S. Joyner <aaron at joyner.ws>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> https://www.trilug.org/mailman/options/trilug/aaron%40joyner.ws
> Welcome to TriLUG: https://trilug.org/welcome


More information about the TriLUG mailing list