- Home
- Tools
- Developer Tools
- Cron Expression Explainer
- Cron Expression for Every Monday
Cron Expression for Every Monday
0 0 * * 1 runs a job every Monday at 00:00. Change the time below, and see why the first Monday of the month takes a workaround.
At 00:00 on Monday
| Field | Value | Matches |
|---|---|---|
| Minute | 0 | 0 |
| Hour | 0 | 0 |
| Day of month | * | every day of the month |
| Month | * | every month |
| Day of week | 1 | Monday |
Next 10 runs
Cron goes by the clock of the machine it runs on. These are the runs on a machine in your time zone.
One run a week
In 0 0 * * 1 the 1 in the last field is Monday. In a crontab the week is numbered from Sunday as 0 to Saturday as 6, and MON means the same. The two zeros in front are the minute and the hour, so the job runs at 00:00, in the night from Sunday to Monday. For Monday morning, change the hour: 0 9 * * 1.
| Expression | Runs |
|---|---|
| 0 0 * * 1 | At 00:00 on Monday |
| 0 9 * * 1 | At 09:00 on Monday |
| 0 0 * * MON | At 00:00 on Monday |
| 0 0 * * 1,4 | At 00:00 on Monday and Thursday |
| 0 0 1-7 * 1 | At 00:00 on the 1st to 7th of the month and on Monday |
The first Monday of the month
The obvious attempt is in the last row of the table: Monday, and a date from 1 to 7. It doesn't work. When both day fields are filled in, cron runs the job when either one matches, so 0 0 1-7 * 1 runs on the first seven days of the month and on every Monday besides.
The way that does work is to let cron pick the seven dates and the command check the weekday:
0 0 1-7 * * [ "$(date +\%u)" = 1 ] && /path/to/job
date +%u gives 1 for Monday. The backslash is needed because cron treats a bare % as a line break.
Every other Monday
That can't be written as an expression either. Run the job every Monday and let the script decide whether this is its week.
The cron expression explainer has the full syntax: the five fields, lists, ranges and steps, and how day of month and day of week work together.