Cron cheatsheet

Syntax

* * * * * /path/to/command.sh
1 2 3 4 5 6
Key Contents Range
1 Minute of hour 0-59
2 Hour of day 0-23
3 Day of month 1-31
4 Month of year 1-12
5 Day of week 0-6 (0=Sunday)
6 Command to run (full path)

Crontab examples

#comments start with #.
#you cannot mix comments and commands on the same line.
#force command output to be mailed to specific user
MAILTO="admin@myserver.com"
#or send all command output to the bitbucket
MAILTO=""
/5 * * * * /usr/bin/mrtg /data/mrtg/172.25.0.1.cfg --logging /var/log/mrtg.log
2 11,15 * * * /data/scripts/portprobe-0.5.pl

*/5 means run every 5 minutes
2 11,15 means run 11:02 and 15:02 every day

Meaning of *

Field
1 Do job every minute, 60 times per hour
2 Do job every hour, 24 times per day
3 Ignore this field and use field 5
4 Do job every month, 12 times per year
5 Ignore this field and use field 3
Asterisk in both field 3 & 5 means job is run every day

Summary

# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +—– day of week (0 - 6) (Sunday=0)
# | | | +——- month (1 - 12)
# | | +——— day of month (1 - 31)
# | +———– hour (0 - 23)
# +————- min (0 - 59)
 
linux/cron.txt · Last modified: 28/09/2021 10:18 by andrew