failover.io
  1. Home
  2. Guides
  3. Crontab syntax

Crontab syntax

The five fields, the four operators, special strings and the traps, with examples you can copy.

Updated 19 November 20265 min read

A crontab line is five time fields followed by the command:

┌───────── minute (0 to 59)
│ ┌─────── hour (0 to 23)
│ │ ┌───── day of month (1 to 31)
│ │ │ ┌─── month (1 to 12)
│ │ │ │ ┌─ day of week (0 to 7)
│ │ │ │ │
0 3 * * 1 /usr/local/bin/weekly-report.sh

This runs the script at 3:00 every Monday. In the day of week field, Sunday is both 0 and 7. To build a line by picking a schedule, use the cron expression generator; to check one, the cron expression tester.

Operators

SymbolMeaningExample
*Every value* * * * * runs every minute
,A list0,30 * * * * runs at minute 0 and 30
-A range0 9-17 * * * runs on the hour from 9:00 to 17:00
/A step*/15 * * * * runs at minute 0, 15, 30 and 45

They combine: 0 8-18/2 * * 1-5 runs every 2 hours from 8:00 to 18:00, Monday to Friday. A step counts from the start of the range, so */7 in the minute field runs at 0, 7, 14 ... 56 and then again at 0, which is 4 minutes later. To start at minute 5, write 5-59/15.

Month and day names

The month and day of week fields also take the first three letters of the name, in any case: JAN to DEC and SUN to SAT. 0 9 * * MON is the same as 0 9 * * 1. The cron on Debian and Ubuntu doesn't accept names in lists or ranges, so MON-FRI may fail there; 1-5 works everywhere.

Special strings

StringSame as
@rebootOnce, when cron starts after boot
@yearly or @annually0 0 1 1 *
@monthly0 0 1 * *
@weekly0 0 * * 0
@daily or @midnight0 0 * * *
@hourly0 * * * *

Day of month and day of week together

When both day fields are set, cron runs on any day that matches either one. 0 9 1 * 1 runs on the 1st of every month and also on every Monday. To run only on the first Monday of the month, set the day of month to 1-7, leave the day of week as *, and check the weekday in the command:

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

Other lines in a crontab

LineWhat it does
# commentA comment. Only at the start of a line; text after a command is part of the command.
PATH=/usr/local/bin:/usr/bin:/binSets the PATH for the lines below it. Cron's default is short.
SHELL=/bin/bashRuns commands with bash instead of sh.
MAILTO=you@example.comWhere cron mails the output. MAILTO="" turns mail off.
CRON_TZ=Europe/ParisTime zone for the schedule. Supported by cronie (Red Hat based systems), not by the cron on Debian and Ubuntu.

In /etc/crontab and /etc/cron.d/, each line has a sixth field before the command: the user to run as.

0 3 * * * root /usr/local/bin/backup.sh

Write % as \% in the command; a bare % ends the command and starts standard input.

Examples

ExpressionRuns
*/5 * * * *Every 5 minutes
0 * * * *Every hour, on the hour
0 */6 * * *Every 6 hours: 0:00, 6:00, 12:00, 18:00
30 2 * * *Every day at 2:30
0 9 * * 1-5Weekdays at 9:00
0 0 * * 0Sundays at midnight
0 0 1 * *The 1st of every month at midnight
0 0 1 1 *January 1st at midnight

Each common schedule has its own page with variations: cron schedules.

Cron formats that are not crontab

WhereDifference
GitHub ActionsFive fields like crontab. UTC unless a timezone key next to cron sets another zone.
Kubernetes CronJobFive fields like crontab. A timeZone setting picks the zone.
Quartz (Java, Spring)Six or seven fields: seconds first, an optional year last. Adds ?, L, W and #.
AWS EventBridgeSix fields with a year, written cron(0 12 * * ? *). One of the two day fields must be ?.

A correct line can still stop running

Syntax is the easy part. A server rebuilt without its crontab or a script that starts failing gives no error anywhere. Add a heartbeat ping after the command, and you get an alert when a run is missed:

0 3 * * 1 /usr/local/bin/weekly-report.sh && curl -fsS -m 10 -X POST https://api.failover.io/heartbeat/<your-monitor-id>

Frequently asked questions

What is the crontab format?

Five fields, minute, hour, day of month, month and day of week, followed by the command. 30 2 * * * means 2:30 every day.

What does */5 mean in cron?

Every 5th value of that field. In the minute field, */5 runs at minute 0, 5, 10 and so on, every 5 minutes.

Is Sunday 0 or 7 in cron?

Both. 0 and 7 both mean Sunday in the day of week field.

Can cron run every 30 seconds?

Not with crontab, which counts in minutes. Run two lines, the second starting with sleep 30;, or use a systemd timer.

Why does my cron job run on the wrong days?

If you set both the day of month and the day of week, cron runs when either matches. Leave one of them as *.