Cron is a program that runs scheduled tasks on Unix based systems. On Linux, the implementation is based on the new Vixie Cron code base.
The basic usage is to create a crontab file containing the following fields:
# Example of job definition: # .---------------- 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) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
About the 'Day of Week' value
If you set the 'Day of Week' value to something other than '*', the cronjob will run on either the specified day of month or the specified day of week.
For instance, this cronjob will run at 2:15AM between the 1st and 7th of every month AND at 2:15AM every Wednesdays. It does not run on the first Wednesdays of each month.
15 2 1-7 * 3 root run-every-wednesdays-and-1-7-every-month
If you wish to run a cronjob on the first Wednesday of each month, you need to add a check with
test $(date %u) -eq 3:
15 2 1-7 * 3 root test $(date +\%u) -eq 3 && run-on-first-wednesdays-every-month
Cronjobs can be added by modifying any of the files below:
/etc/crontab /var/spool/cron/ /etc/crond.d/* /etc/anacrontab
Instead of defining the specific minute, hour, and date for a recurring task, you can use shorthand keywords:
@daily = 0 0 * * *