Glossary Development

Cron

Cron is the scheduler on Unix-like systems that runs commands automatically at times set by a five-field schedule expression.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page

In more detail

The fields are minute, hour, day of month, month and day of week, with * meaning "every" and */5 "every five". For example 30 2 * * 1-5 runs at 02:30 on weekdays. Cron uses the server's time zone, which is a common source of surprises around daylight saving changes. Lists (1,15), ranges (9-17) and steps (*/15) can be combined, day of week runs 0-6 with Sunday as 0 (most versions also accept 7), and a crontab line ends with the command to run. Each user edits their table with crontab -e.

Why it matters

A wrong field silently runs a backup at the wrong time or not at all. Jobs scheduled between 01:00 and 03:00 can be skipped, delayed or run twice on daylight-saving change days, depending on the implementation, so critical jobs are often scheduled in UTC or outside that window. Cron also runs with a minimal environment, so use full paths and redirect output to a log.

Example

# m   h   dom mon dow  command
*/15  *   *   *   *    /usr/local/bin/check-disk.sh
0     3   *   *   0    /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
0     9   1   *   *    /usr/local/bin/monthly-report.sh

These run every 15 minutes, at 03:00 every Sunday, and at 09:00 on the first of each month. Decode any expression with the Cron Expression Explainer.

Common confusion

When both day of month and day of week are restricted, classic cron runs the job if either matches: 0 0 1 * 1 fires on the 1st of the month and on every Monday, not only on Mondays that fall on the 1st.

AdSense Placeholder
Slot: footer_leaderboard