Glossary

Cron job

A command scheduled to run automatically at set times on a Linux server.

In plain English A task the server runs by itself on a timetable, like an alarm clock for jobs. For example, making a backup every night at 3 a.m.

A cron job is a command a Linux server runs automatically on a schedule: every night, every five minutes, every Monday. The cron service checks its schedules every minute and runs whatever is due. Servers use it for backups, certificate renewals, clean-ups, reports and site maintenance tasks.

How a schedule is written

Each line in a crontab has five time fields, then the command:

# minute  hour  day-of-month  month  day-of-week  command
30 3 * * *   /root/backup.sh
*/5 * * * *  cd /var/www/example.com/public && wp cron event run --due-now
0 9 * * 1    /usr/local/bin/weekly-report.sh

The first runs at 03:30 every day, the second every five minutes, the third at 09:00 every Monday. A * means “every”. Edit your own crontab with crontab -e, and root’s with sudo crontab -e.

Things that catch people out

  • Cron runs with a minimal environment. Commands that work in your terminal can fail in cron because PATH is shorter. Use full paths, such as /usr/bin/php.
  • Output goes nowhere unless you send it somewhere. Add >> /var/log/myjob.log 2>&1 to keep a record.
  • Times are in the server’s time zone, often UTC. Check with timedatectl.

WordPress has its own “cron” that only runs when someone visits the site. On quiet sites, replace it with a real cron job calling WP-CLI, as in the example above.