Field breakdown
Minute 0, hour 0, day of month 1, month *, day of
week *. Because the day-of-week field is a wildcard, the day-of-month restriction applies
cleanly: the job runs on the 1st whatever weekday that happens to be.
This is the schedule where the OR rule bites hardest. 0 0 1 * 1 looks like "the 1st,
if it is a Monday" but actually means "the 1st of every month, plus every Monday"
— roughly 64 runs a year rather than one or two. Keep day-of-week as * unless you
genuinely want both sets of days. See why this matters for the full
explanation, and for cron's other well-known trap: daylight saving time.
Typical uses
- Billing runs, invoice generation and usage rollups for the month just ended.
- Monthly reports, retention snapshots and archive rotation.
- Resetting quotas or counters that are defined per calendar month.
- Long-interval maintenance: pruning old backups, vacuuming a database, rotating credentials.
If the job summarises the previous month, give it a little air. Running at exactly 00:00 on the 1st
means competing with every daily midnight job at the same instant, and any event that arrived a few
seconds late will be missed. 15 1 1 * * is a friendlier choice.
Every third month is not "every quarter from now"
Steps in the month field are anchored to January, not to the day you installed the crontab.
0 0 1 */3 * expands to months 1, 4, 7 and 10 — January, April, July and October. If
your quarters begin in February you must list them: 0 0 1 2,5,8,11 *.
Using it
# crontab, both forms are equivalent
0 0 1 * * /usr/local/bin/monthly-invoice.sh
@monthly /usr/local/bin/monthly-invoice.sh
# the last day of the month instead — cron cannot express it directly
0 3 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /usr/local/bin/eom.sh
The guard is true only on whichever of days 28 to 31 is actually the last of that month. The
backslash before the percent sign is required: in a crontab an unescaped % becomes a
newline.
Variations
| Expression | Runs |
|---|---|
| 0 0 1 * * | Midnight on the 1st. Same as @monthly. |
| 15 1 1 * * | 01:15 on the 1st — clear of the midnight rush. |
| 0 0 1,15 * * | Twice a month, on the 1st and the 15th. |
| 0 0 1 */3 * | Quarterly: 1 January, 1 April, 1 July, 1 October. |
| 0 0 1 1 * | Once a year, on 1 January. Same as @yearly. |
| 0 6 2 * * | 06:00 on the 2nd — useful when the 1st is a holiday everywhere. |