Open Your Crontab
crontab -eThis opens your personal crontab in an editor; on Debian and Ubuntu you may be asked to pick one the first time. Add a line, save, and close: the job is active at once. Each user has a separate crontab; sudo crontab -e edits root's. If the command is missing, install cron on Debian and Ubuntu or cronie on AlmaLinux and Rocky Linux. To see what is already scheduled, see how to list cron jobs.
The Five Fields
*/5 * * * * /usr/local/bin/check-site
| | | | |
| | | | day of week (0-7, 0 and 7 are Sunday)
| | | month (1-12)
| | day of month (1-31)
| hour (0-23)
minute (0-59)*: every value.,: a list, as in1,15.-: a range, as in1-5./: a step, as in*/10for every tenth.
Times are in the server's time zone; check it with timedatectl.
Common Schedules
| Fields | Runs |
|---|---|
*/ | Every 5 minutes |
0 * * * * | Every hour, on the hour |
30 2 * * * | Daily at 02:30 |
0 3 * * 0 | Sundays at 03:00 |
0 4 1 * * | First day of each month |
0 9- | Hourly, 09:00 to 17:00, weekdays |
If both day of month and day of week are set, the job runs when either one matches.
Shortcuts
Instead of the five fields you can write @hourly, @daily, @weekly, @monthly, or @yearly, which run at the start of that period, and @reboot, which runs once when cron starts after a boot.
Cron's Minimal Environment
Cron does not load your .bashrc. It runs commands with /bin/sh, a short PATH, and your home folder as working directory. A command that works in your terminal can fail in cron for that reason alone.
- Use absolute paths:
/usr/bin/php, notphp.command -v phpshows the full path. - Or set PATH at the top of the crontab:
PATH=/usr/local/bin:/usr/bin:/bin. - Escape percent signs: cron treats
%as a line break, so write\%, or move the command into a script. - No secrets in the crontab: let the script read passwords from a file with mode 600.
Log the Output
30 2 * * * /home/deploy/bin/backup.sh >> /home/deploy/logs/backup.log 2>&1>> appends standard output to the log and 2>&1 adds the errors. The log folder must exist and be writable by the crontab's owner.
Stop Overlapping Runs with flock
*/5 * * * * /usr/bin/flock -n /tmp/sync.lock /home/deploy/bin/sync.shIf the previous run still holds the lock, -n makes the new one exit at once. The lock is released when the job ends; the file itself can stay.
Mail with MAILTO
MAILTO=YOUR_EMAILPlaced at the top of the crontab, it sends the output of every job by mail, if the server can send mail; see how to send email from the command line. MAILTO="" turns it off.
When a Job Did Not Run
- Check the service:
systemctl status cronon Debian and Ubuntu,systemctl status crondon AlmaLinux and Rocky Linux. - Read the log:
journalctl -u cronorjournalctl -u crond; on AlmaLinux and Rocky Linux also/var/log/cron. - Check that the script is executable:
chmod +x. - Run it with an empty environment:
env -i /bin/sh -c '/home/deploy/bin/backup.sh'. - Make sure the last line of the crontab ends with a newline.
systemd Timers as an Alternative
A systemd timer does the same job with logs in the journal, catch-up runs after downtime, and resource limits. See systemd unit files; a complete timer example is in the BorgBackup guide.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations