Practical technical guides / Core IT: operations and scheduling

Cron Joins Day-of-Month and Day-of-Week With OR: Why 1-7 * MON Is Not the First Monday

Restricted cron day fields combine with OR, and cronie and robfig/cron disagree on whether */2 is a star. Measured for December 2026, with a safer schedule design.

By Sandeep Belgavi · Published 2026-11-28

Restricted cron day fields combine with OR, and cronie and robfig/cron disagree on whether */2 is a star. Measured for December 2026, with a safer schedule design.

The first-Monday job that ran ten times

A schedule like 0 9 1-7 * MON reads naturally as "09:00 on the first Monday of the month": the first Monday always falls between the 1st and the 7th, so restricting both day fields should pick it out. It does not. On a standard cron it fires at 09:00 on every one of the first seven days of the month and on every Monday. In December 2026 that is ten runs instead of one.

The surprise has a precise source. Cron has two day fields, day of month and day of week, and when both are restricted it joins them with OR, not AND. The rule is old, documented and portable, which is why it keeps catching people: nothing about the expression looks wrong, and a test that only checks one month boundary passes.

A second trap sits next to it. Whether a field counts as "restricted" is decided differently by different implementations. A field written as */2 is restricted in some parsers and unrestricted in others, so the same line can run twice a month on one system and eighteen times on another. This guide shows both rules from the source, measures them, and gives a schedule design that does not depend on either.

What the specifications say

The POSIX description of crontab spells out four cases for the day fields. If month, day of month and day of week are all asterisks, every day matches. If day of month or month is restricted and day of week is an asterisk, the month and day-of-month fields decide. If only day of week is restricted, only those weekdays match. And if day of month or month is restricted and day of week is also restricted, a day matches when it satisfies either the month and day of month or the day of week.

The cronie manual page, which ships on many Linux distributions, says the same in plainer words: if both day fields are restricted, meaning they do not contain the * character, the command runs when either field matches. Its own example is 30 4 1,15 * 5, which runs at 04:30 on the 1st and 15th and on every Friday.

Where implementations disagree: is a star with a step still a star

The phrase "do not contain the * character" hides the second trap. In cronie's parser (src/entry.c in release 1.7.2), the day-of-month field is marked as a star when the first character of the field is *. That flag is set before the step is parsed, so */2 counts as unrestricted. The matcher in cron.c then uses AND whenever either day field carries the star flag.

robfig/cron v3.0.1, the Go library that Kubernetes lists in its go.mod and uses for CronJob schedules, takes a different view. Its parser sets a star bit for * or ?, and then clears it when the step is greater than 1. Its dayMatches function uses AND only when either field still has the star bit, and OR otherwise. So */2 is a restricted field there.

The Python library croniter 7.0.0 (released 9 November 2026) behaves like robfig by default and also offers a day_or=False option that switches to AND for restricted fields.

Measured: December 2026 under each rule

The companion example cron_day_fields_or_rule implements both star rules in about 80 lines of standard-library Python and lists the days each schedule fires in December 2026. A test cross-checks the robfig rule against croniter 7.0.0, installed in a virtual environment pinned to packages available on 28 November 2026; all six schedules agreed day for day.

Schedulecronie rulerobfig and croniter defaultWhat the author probably meant
0 9 1-7 * MON10 runs: 1st to 7th, plus the 14th, 21st and 28th10 runs, the same days1 run, Monday the 7th
0 9 */2 * MON2 runs: Monday the 7th and the 21st18 runs: every odd day plus every MondayOdd-day Mondays, or every other Monday
0 9 1-31/2 * MON18 runs18 runsSame as above
0 9 * * MON4 runs4 runsEvery Monday
0 9 1,15 * FRI1st, 4th, 11th, 15th, 18th, 25thSame 6 daysThe documented OR example

The second row is the dangerous one. A team that tests */2 * MON on a Linux host with cronie sees two runs a month and moves the job to a Kubernetes CronJob. The same line now runs eighteen times. Neither system is wrong according to its own documentation; they disagree about what a star is.

Designing schedules that mean one thing

The reliable fix for "first Monday", "last Friday" and similar rules is to stop asking cron to express them. Schedule the job broadly and let the job decide.

from datetime import date

def is_first_monday(d: date) -> bool:
    return d.weekday() == 0 and d.day <= 7

# cron: 0 9 * * MON   (every Monday; restricted day of week only, no OR involved)
if not is_first_monday(date.today()):
    raise SystemExit(0)   # exit quietly; log the skip if you audit runs

For Kubernetes, the same guard works inside the container. Keep the guard in the job, not in a wrapper script nobody reviews, and make it use the same time zone as the schedule. Kubernetes CronJobs accept a timeZone field; on cron hosts the daemon's time zone or a CRON_TZ line applies, depending on the implementation.

Some practical rules follow from the table:

  • Never restrict both day fields unless you want OR. If you need both constraints, restrict one in cron and check the other in code.
  • Do not use */n in a day field if the schedule must behave the same on cronie and on robfig-based schedulers. Write an explicit range such as 1-31/2, which every implementation treats as restricted, or move the logic into the job.
  • Write the intended dates into the pull request. A reviewer can compare a list of dates; very few reviewers can evaluate cron precedence rules in their head.
  • Test schedules by enumerating a month, not by evaluating one timestamp. The OR rule only shows up when you look at the whole month.

Failure modes in practice

A first-Monday billing summary at Belgavi's Book Store illustrates the cost. Tanishka schedules 0 9 1-7 * MON to email the monthly returns report to the finance mailbox. The job is idempotent per run but not per month, so it sends ten reports in December, three of them on days when the month has barely started. Nothing errors. The finance team notices on the 4th.

The reverse also happens. A job that should run on odd days, written as */2 * MON on a host where it ran twice a month, is moved to Kubernetes and suddenly runs eighteen times. If it writes to a shared ledger without an idempotency key, the duplication is real damage, not noise.

Monitoring rarely catches either case, because schedulers report successful runs. What catches them is a run-count expectation: a check that alerts when a job that should run once a month has run twice.

Verification checklist

  • For every schedule that restricts both day fields, list a month of fire dates and attach it to the change.
  • In CI, run the companion example or a croniter enumeration over the next twelve months and compare against the intended dates.
  • Record which scheduler executes each job (cronie, systemd timers, Kubernetes, a cloud scheduler) next to the expression; the same text is not portable.
  • Add a guard in the job for calendar rules cron cannot express, and a test for the guard over at least two years of dates.
  • Alert on unexpected run counts per period, not only on failures.

Cron is a good clock and a poor calendar. Use it to wake the job; let the job decide whether today is the day.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Time-sensitive sources are limited to material dated on or before 2026-11-28. Companion code: Sandeep-BA/agent-decision-lab/examples/python/cron_day_fields_or_rule. Views are my own and do not represent any employer, past or present.