Crontab Syntax with Practical Examples
Edit your jobs with crontab -e and list them with crontab -l.
# .---------------- minute (0-59)
# | .------------- hour (0-23)
# | | .---------- day of month (1-31)
# | | | .------- month (1-12)
# | | | | .---- day of week (0-7, Sunday is 0 or 7)
# | | | | |
# * * * * * command_to_run
Examples:
15 10 * * * /path/script.sh # every day at 10:15
*/5 * * * * /path/script.sh # every 5 minutes
0 3 * * 0 /path/backup.sh # Sundays at 03:00
0 8 1 * * /path/report.sh # 1st of every month at 08:00
@reboot /path/start.sh # at boot
Log the output (otherwise errors are lost):
15 10 * * * /path/script.sh >> /var/log/script.log 2>&1
If a job doesn't run:
- Cron has a minimal PATH: use absolute paths to commands and scripts.
%has a special meaning in crontab, escape it as\%.- Check the logs:
grep CRON /var/log/syslogorjournalctl -u cron.
Handy checker: crontab.guru.