Cron runs commands on a schedule: backups at night, cleanup of temporary files, reports on Mondays. The five-field syntax looks simple, but it is easy to get wrong — the job does not run, runs every minute, or twice as often as intended. Here are the format, examples for every case and the reasons a job "does not work".

Five fields

┌───── minute (0–59)
│ ┌───── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌───── month (1–12)
│ │ │ │ ┌───── day of week (0–7, 0 and 7 are Sunday)
│ │ │ │ │
30 2 * * * /usr/local/bin/backup.sh

Special characters:

Examples

ExpressionWhen it runs
*/5 * * * *Every 5 minutes
0 * * * *At the start of every hour
30 2 * * *Every day at 02:30
0 9 * * 1-5Weekdays at 09:00
0 3 * * 0Sundays at 03:00
0 0 1 * *Midnight on the first day of every month
15 8,20 * * *Twice a day: at 08:15 and 20:15
0 */6 * * *Every 6 hours: at 0, 6, 12 and 18
@rebootOnce after the system boots

Syntax traps

If in doubt, paste the expression into the cron decoder: it describes the schedule in words and shows the next runs in the time zone you need.

Why a job does not run

  1. A different environment. Cron runs commands with a minimal PATH (usually /usr/bin:/bin) and without your variables. Use full paths to programs or set PATH= at the top of the crontab.
  2. No newline at the end of the file. The last crontab line without a newline may be ignored.
  3. Permissions and owner. The script must be executable (chmod +x), and files in /etc/cron.d/ must be owned by root and not writable by group and others. Linux permissions are covered in the article on chmod.
  4. The format of /etc/crontab and /etc/cron.d differs: the sixth field there is the user name. A line from your personal crontab -e copied there without a user name will not work.
  5. Time zone. Cron uses system time; check timedatectl.

To see errors, redirect output to a log: 30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1. The runs themselves are visible in journalctl -u cron (crond on RHEL) or in /var/log/syslog.

systemd timers instead of cron

Modern Linux systems increasingly use systemd timers instead of cron. They have advantages: a journal entry for every run in journalctl, running missed jobs after the server is switched on (Persistent=true), a random delay so hundreds of servers do not hit a service at once, and resource limits. The schedule is set with an OnCalendar line:

OnCalendar=*-*-* 02:30:00      # every day at 02:30
OnCalendar=Mon..Fri 09:00      # weekdays at 09:00
OnCalendar=*:0/15              # every 15 minutes

The Cron page translates a crontab expression into OnCalendar and gives ready .timer and .service files right away. If the job runs a service, you can give it a sandbox with systemd hardening.