The five fields
A standard cron expression has five fields separated by spaces:
| Field | Values | Example |
|---|---|---|
| Minute | 0-59 | */15 every 15 minutes |
| Hour | 0-23 | 9-17 nine to five |
| Day of month | 1-31 | 1 the first |
| Month | 1-12 or JAN-DEC | JAN,JUL |
| Day of week | 0-7 or SUN-SAT (0 and 7 are Sunday) | 1-5 weekdays |
* means every value, a-b a range, a,b a list and /n a step. Shortcuts: @hourly, @daily, @weekly, @monthly, @yearly.
Traps that catch everyone
- Day of month and day of week together are OR, not AND.
0 0 13 * 5runs on every 13th and every Friday, not only on Friday the 13th. - Time zones: cron uses the server's time zone, often UTC in containers and cloud schedulers. A job set for 09:00 may run at 14:30 local time.
- Daylight saving: jobs between 01:00 and 03:00 can run twice or not at all on the night the clocks change. Schedule critical jobs outside that window or in UTC.
- Six or seven fields: Quartz, Spring and some cloud schedulers add seconds (and years). Those are not standard crontab.
Know when a job stops running
Cron's worst failure is silence: a job that stops running because a server was replaced, a crontab was overwritten or a script now exits early. Nothing errors, and the backup or invoice run is simply missing weeks later.
Heartbeat monitoring fixes that: the job pings a URL when it finishes, and you are alerted when the ping does not arrive on schedule. See cron job monitoring.