Cron every Monday at 9 AM (0 9 * * 1) and the day-of-month OR trap

Open this example in the tool

Try it in the tool

Cron Expression Parser

Read cron schedules in plain English and see when they run next.

Cron Expression Generator

Pick a schedule, get the cron expression and its next run times.

0 9 * * 1 runs once a week, on Monday at 09:00. The cron parser says “At 09:00, on Monday” and lists a run every seven days. You can write the day by name: 0 9 * * MON. Sunday is 0 (or 7) and Saturday is 6, as in weekdays at 9 AM.

0 9 * * 1 /usr/local/bin/weekly-digest.sh >> /var/log/digest.log 2>&1

The OR trap

This is the best-known surprise in cron. Normally the five fields are joined with AND: every field must match. But when the day-of-month and the day-of-week are both restricted (neither is *), classic cron joins just those two with OR: the job runs when either matches.

Put this in the parser:

0 9 1 * 1
→ At 09:00, on day 1 of the month or on Monday

The list of runs shows 26 October (a Monday), 1 November (the 1st, a Sunday), 2 November (a Monday), then every Monday. It does not mean “the Monday that falls on the 1st”. The same applies to ranges: 0 9 1-7 * 1, which people write to mean the first Monday of the month, fires on days 1 through 7 and on every Monday, so on 26 October, 1 November, 2 November, 3 November, 4 November, and so on.

The first Monday of the month

Since the fields cannot say it, run the job every Monday and let the shell check the date. A Monday whose day number is 1 to 7 is the first Monday:

0 9 * * 1 [ "$(date +\%d)" -le 7 ] && /usr/local/bin/monthly-meeting.sh

Two details: the % characters have to be escaped as \% in a crontab, because an unescaped % is treated as the end of the command; and the condition lives in the command, so the daemon still starts the shell every Monday. For the last Monday, test that adding seven days moves into the next month: [ "$(date -d '+7 days' +\%m)" != "$(date +\%m)" ] (GNU date).

Other weekly schedules

Goal Expression
Every Sunday at 03:00 0 3 * * 0
Mondays and Thursdays at 09:00 0 9 * * 1,4
Every Friday at 17:30 30 17 * * 5
Every other week not possible in cron; run weekly and keep a flag file or compare the week number in the script

Time zone

The hour is the server’s. On a UTC server 0 9 * * 1 is Monday 16:00 in Hanoi (UTC+7). When you convert across midnight, the weekday changes with the hour: Monday 06:00 in Hanoi is Sunday 23:00 UTC, so you would write 0 23 * * 0. Run the converted expression through the cron builder and check the listed dates. More on this in cron and time zones.

For once a month, see first day of the month and last day of the month; both involve the day-of-month field, which is where the OR rule can bite.

Frequently asked questions

What is the cron expression for every Monday at 9 AM?

0 9 * * 1, or 0 9 * * MON. Minute 0, hour 9, any day of the month, any month, and day of the week 1.

Why does 0 9 1 * 1 run far more often than I expected?

When both the day-of-month and the day-of-week fields are restricted, standard cron runs the job when either one matches. 0 9 1 * 1 means on the 1st of the month OR on any Monday, not on a Monday that is the 1st.

How do I run on the first Monday of the month?

Cron cannot say it in the fields. Run every Monday and test the date in the command: 0 9 * * 1 [ "$(date +\%d)" -le 7 ] && /path/job.sh. Only a Monday with a day number from 1 to 7 passes.

Is Sunday 0 or 7 in a weekly schedule?

Both are Sunday in most implementations. Use 0 for portability.

More in this reference