Pick how often the job should run and the generator writes the cron expression, explains it in plain words and shows the next runs. Add the command to get the full line for your crontab. Cron uses the server's time zone, so check it with timedatectl before picking a time.
Add the line to your crontab
- Run
crontab -eon the server. - Paste the crontab line on a new line at the end, and save.
- Check it with
crontab -l. Cron picks up the change on its own.
Use full paths in the command, like /usr/bin/php, because cron runs with a short PATH. More on that in what is a cron job.
The five fields
| Position | Field | Values |
|---|---|---|
| 1 | Minute | 0 to 59 |
| 2 | Hour | 0 to 23 |
| 3 | Day of month | 1 to 31 |
| 4 | Month | 1 to 12 |
| 5 | Day of week | 0 to 7, Sunday is 0 or 7 |
* is every value, */10 is every 10th, 1-5 is a range and 1,15 is a list. To check an expression you already have, paste it into the cron expression tester. Common schedules each have their own page: every 5 minutes, every hour and more.
What a cron expression can't say
Some schedules don't fit the five fields. Every 90 minutes doesn't, because minutes reset every hour; use two lines (0 0-21/3 * * * and 30 1-22/3 * * *) or a script that checks the time. The last day of the month doesn't either in standard cron; run on days 28 to 31 and let the script exit unless tomorrow is the 1st. If you set both a day of the month and days of the week, standard cron runs on either, not only when both match.
Frequently asked questions
How do I write a cron expression?
Five fields: minute, hour, day of month, month and day of week, then the command. Pick a schedule in the generator above to get the expression and a plain-English check of what it means.
What is the cron expression for every day at midnight?
0 0 * * *. For 3:00 every day, it is 0 3 * * *.
What is the cron expression for weekdays only?
Put 1-5 in the day of week field. 0 9 * * 1-5 runs at 9:00 Monday to Friday.
Which time zone does the cron job use?
The server's. The generator shows the next runs in your browser's time zone and in UTC; if your server runs in UTC, use the UTC column.
How do I know the cron job actually ran?
Tick "Add a heartbeat ping". The job then pings a monitor after each successful run, and you get an alert when a ping is late. See how to monitor cron jobs.