Cron Cheat Sheet: The Five Fields and Twelve Schedules You Will Copy
The five fields
| Field | Range | Notes |
|---|---|---|
| minute | 0 to 59 | */15 means 0, 15, 30, 45 |
| hour | 0 to 23 | 0-23/2 is every even hour |
| day-of-month | 1 to 31 | Interacts with day-of-week (below) |
| month | 1 to 12 | Names (JAN) are accepted by many daemons, not by the checker here |
| day-of-week | 0 to 7 | 0 and 7 are both Sunday |
| command | the rest of the line | Run by /bin/sh; an unescaped % means newline |
Two rules that surprise people. A restricted day-of-month and a restricted day-of-week match with OR: 0 0 13 * 5 fires on the 13th and on every Friday. And ranges are inclusive at both ends.
Twelve schedules
| Expression | Meaning |
|---|---|
*/15 * * * * | Every 15 minutes (96 times a day) |
17 * * * * | Hourly at :17, off the :00 mark where every other job on the host lands |
0 4 * * * | Daily at 04:00 |
0 22 * * 1-5 | 22:00 Monday to Friday |
23 0-23/2 * * * | Every two hours at :23 |
0 9 1-7 * 1 | Day 1 to 7 or a Monday, because of the OR rule. This does not mean "the first Monday"; gate that inside the job |
30 2 * * * | Daily at 02:30, which does not exist on the spring-forward day in zones that skip that hour |
0 0 29 2 * | 29 February only: once every leap year |
@daily | 0 0 * * * |
@reboot | When the cron daemon starts, which can be before the services you depend on |
5 0 * * * | 00:05 daily |
0 6,18 * * * | 06:00 and 18:00. */12 would be 00:00 and 12:00 |
Paste any of them into the checker to see the next runs.
cron or a systemd timer
| Need | cron | systemd timer |
|---|---|---|
| Run a job missed during downtime | Nothing happens | Persistent=true runs it once at next start |
| Spread load across a fleet | Hand-rolled sleep $RANDOM | RandomizedDelaySec= |
| Calendar syntax | Five fields | OnCalendar=, checked with systemd-analyze calendar |
| Per-job logs | Mail, or nothing | journalctl -u name.service |
| Hosts without systemd | Everywhere | No |
Cron is portable and simple. A timer is a service with dependencies and fixes the gaps above. On a systemd fleet prefer timers; in a container or a NAS cron is the honest answer.