The five fields
A cron expression is five fields separated by spaces, telling a scheduler when to run a job:
In order, left to right:
| Minute | 0-59 |
| Hour | 0-23 |
| Day of the month | 1-31 |
| Month | 1-12 |
| Day of the week | 0-6 (Sunday = 0) |
The job runs whenever the current time matches every field.
Special characters
*any value.,a list:1,15is the 1st and the 15th.-a range:1-5is Monday to Friday in the last field./a step:*/10in the minute field is every 10 minutes.
Common schedules
*/5 * * * * | Every 5 minutes |
0 * * * * | Every hour, on the hour |
0 0 * * * | Every day at midnight |
30 8 * * 1-5 | 08:30 on weekdays |
0 0 1 * * | Midnight on the 1st of every month |
0 3 * * 0 | 03:00 every Sunday |
Paste any expression into the Cron Expression Explainer to read it in plain words and see its next run times.
Things that catch people out
- Time zone: cron uses the server's clock, which is often UTC.
- Day of month and day of week together: if both are set, the job runs when either matches, not both.
- Seconds: standard cron has no seconds field. Some systems, such as Quartz and Spring, add one at the start, making six fields.
Expressions that do not do what they seem
| Expression | Meant to be | Actually runs |
|---|---|---|
0 9 1-7 * 1 | 09:00 on the first Monday | 09:00 on each of days 1 to 7, and on every Monday |
*/15 9-17 * * 1-5 | Every 15 minutes, 9 to 5 | 09:00 to 17:45 on weekdays, including the 17:00 hour |
0 0 31 * * | The last day of the month | Only in the seven months with 31 days |
0 0 29 2 * | Once a year | Only in leap years |
For the first Monday, run on days 1 to 7 and check the weekday inside the script.
Shortcuts
Many cron versions accept nicknames: @hourly, @daily, @weekly, @monthly, @yearly, and @reboot, which runs once when the machine starts.
Daylight saving time
On a server that follows local time, a job set between 01:00 and 03:00 can be skipped on the night the clocks go forward or run twice when they go back, depending on the cron version. Schedule important jobs outside those hours, or run the server on UTC.