cron is the daemon process that executes scheduled commands, crontab is the program used to modify crontab files i.e. a per user file that contains instructions for cron.
/var/spool/cron is the location of the root and user crontab files, which
should be modified through
crontab -e command.
crontab -ldisplay crontab file.
crontab -rremove crontab file.
crontab -vdisplay the last time you edited your crontab file.
Some Linux distributions also have
scripts inside those directories will be executed every hour/day/week/month with
You can change shell by specifying
SHELL=/bin/bash in crontab file.
Cron passes a minimal set of environment variables to your jobs. You can set
PATH variable at the top of the script.
On a default installation the cron jobs get logged to
cron will not catchup and run past queries.
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) # | | | | | # * * * * * command
,is used to specify a list e.g
-is used to spefiy ranges and they can be combined with lists e.g.
/character can be used to introduce a step e.g.
2/5which means starting at 2 then every 5
- ranges and steps can be combined e.g.
*/5starting at 0 then every 5
\cannot be used to extend a command over multiple lines
@rebootrun once, at startup.
@yearlyrun once a year, i.e.
0 0 1 1 *
@monthlyrun once a month,
0 0 1 * *
@weeklyrun once a week, i.e.
0 0 * * 0
@dailyrun once a day, i.e.
0 0 * * *
@hourlyrun once an hour, i.e.
0 * * * *
Check cron’s logs
sudo grep CRON /var/log/syslog
sudo grep CRON /var/log/messages
Check that cron is running
strace the cron process to see what it's doing:
sudo strace -f -p `pidof cron`
command at 12:11 on the first day of the month.
11 0 1 * * command
command at 6:15 on every day.
15 6 * * * command
command every hour
0 * * * * command
command at 00:30 on 1st day of January, June and December
30 0 1 1,6,12 * command
command at 20:00 on every weekday (Mon-Fri) but only in October
0 20 * 10 1-5 commnad
command at midnight on 1st, 10th and 15th of each month
0 0 1,10,15 * *