Cron runs commands on a schedule on Linux servers, and control panels use the same format for their scheduled tasks.
The 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)
│ │ │ │ │
* * * * * command
| Symbol | Meaning | Example |
|---|
* | Every value | * in hours = every hour |
, | A list | 1,15 = the 1st and the 15th |
- | A range | 1-5 = Monday to Friday |
/ | A step | */10 in minutes = every 10 minutes |
Examples
| Schedule | When it runs |
|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | At the start of every hour |
30 2 * * * | Every day at 02:30 |
0 9 * * 1-5 | Weekdays at 09:00 |
0 3 * * 0 | Sundays at 03:00 |
0 0 1 * * | Midnight on the first of each month |
Editing and checking
crontab -e # edit your jobs
crontab -l # list your jobs
Avoiding surprises
- Cron runs with a minimal environment: use full paths to programs and files.
- The time is the server's timezone, which may not be yours.
- Send output to a log file so failures are visible, e.g.
>> /var/log/backup.log 2>&1. - Spread heavy jobs out instead of starting them all at midnight.