Cron

Cron for the First Monday of the Month

The obvious expression for this is a well-known trap — most cron implementations don't apply the logic you'd expect.

0 9 1-7 * 1

It's tempting to write 0 9 1-7 * 1 and assume it means "day-of-month 1 through 7, AND it's a Monday" — which would correctly match only the first Monday. But on Vixie cron and most of its descendants (used by cron on Linux and macOS), when both the day-of-month and day-of-week fields are restricted (neither is left as *), the two are combined with OR, not AND. That means this expression actually runs on every day from the 1st through the 7th and separately on every Monday of the month — far more often than intended.

The reliable fix is the same one used for last-Friday-of-the-month jobs: schedule every Monday with 0 9 * * 1, then have the script check whether today's date is 7 or less — if so, it's the first Monday, and the script proceeds; otherwise it exits. Cron's date fields alone can't express "the first occurrence" safely.

Want to build a different schedule, or check how a related expression behaves? Open this exact expression in the full Cron Expression Builder to edit it directly.

Related

Related