[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 15:30:07 EDT 2025


I'm doing well, thanks.  I hope you are, as well.  :)  I agree that trying
to express loops in C as English grammar (or vice versa) is fraught with
the potential for miscommunication.  This is especially true when the
syntax in the crontab looks like "divide by two", but you end up with odd
numbered answers.  If it's any consolation, minutes work like you expect,
but hours and months don't, so... nothing makes sense in the abstract.  Day
of the week is even worse, because it's 0-7 *inclusive*, where 0 and 7 both
represent Sunday, so depending on what *you* think of as the first day of
the week, */2 might surprise you, or it might seem perfectly cromulent.
When in doubt, you just have to read the code.

Aaron S. Joyner

On Thu, Aug 28, 2025 at 2:12 PM Brian via TriLUG <trilug at trilug.org> wrote:

> On 8/28/25 13:07, Aaron Joyner via TriLUG wrote:
> > 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.
>
> Always glad to hear you chime in, Aaron!  I hope you're thriving.
>
> And I guess this is where my mental logic doesn't match up with cron
> logic.
>
> Given [a, b, c, d, e, f, g, h],
>
> "every second item" to me distinctly means [b, d, f, h] and most
> certainly not [a, c, e, g].  "First" (in the original list) is not in
> the set "every second" because "first" is not a "second".  "Second" is
> "second", so "every second" should start with the first "second"
> (confusing enough?).
>
> Anyway, no amount of me defending my logic will change what cron
> actually does, so thank you to both Paul and Aaron for the responses!
>
> Cheers,
> -B
>
> --
> 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