I have a hard time remembering the crontab file format, so I thought I'd share an example crontab file here today. This is the root crontab file from a CentOS Linux server, specifically a server I use in a test environment.
As you can see in the example crontab file below, I include a crontab format statement at the top of my crontab file to help me remember the format. After that initial documentation, there are a series of Linux commands that I run at various times during the day to help keep things running smoothly.
Given that introduction, here's my example CentOS Linux crontab file:
#-------------------------------------------------- # example unix/linux crontab file format: #-------------------------------------------------- # min,hour,dayOfMonth,month,dayOfWeek command # # field allowed values # ----- -------------- # minute 0-59 # hour 0-23 # day of month 1-31 # month 1-12 (or names, see below) # day of week 0-7 (0 or 7 is Sun, or use names) # #-------------------------------------------------- # run the drupal cron process every hour of every day 0 * * * * /usr/bin/wget -O - -q -t 1 http://localhost/cron.php # run this apache kludge every minute of every day * * * * * /var/www/devdaily.com/bin/check-apache.sh # generate links to new blog posts twice a day 5 10,22 * * * /var/www/devdaily.com/bin/mk-new-links.php # run the backup scripts at 4:30am 30 4 * * * /var/www/devdaily.com/bin/create-all-backups.sh # re-generate the blog "categories" list (four times a day) 5 0,4,10,16 * * * /var/www/devdaily.com/bin/create-cat-list.sh # reset the contact form just after midnight 5 0 * * * /var/www/devdaily.com/bin/resetContactForm.sh # rotate the ad banners every five minutes 0,20,40 * * * * /var/www/bin/ads/freshMint.sh 5,25,45 * * * * /var/www/bin/ads/greenTaffy.sh 10,30,50 * * * * /var/www/bin/ads/raspberry.sh 15,35,55 * * * * /var/www/bin/ads/robinsEgg.sh
As mentioned, this is the root crontab file on a CentOS Linux system, and when I'm logged in as the root user, I edit this file using the following crontab command:
crontab -e
If you haven't seen that command before, here's what it does:
kill -HUP command to that daemon, but I don't know that for a fact).(Hmm, I'll dig into what this actually does, and put another post out here when I learn that.)
For more information on the Linux crontab format, you can view the crontab man page by issuing the following command:
man 5 crontab
(The regular man crontab command gives you help on the crontab command, not the crontab file format.)
This command gives you the following useful information (and much more):
The time and date fields are: field allowed values ----- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names) A field may be an asterisk (*), which always stands for "first-last". Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an "hours" entry specifies execution at hours 8, 9, 10 and 11. Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: "1,2,5,9", "0-4,8-12". Step values can be used in conjunction with ranges. Following a range with "<number>" specifies skips of the number’s value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2". Names can also be used for the "month" and "day of week" fields. Use the first three letters of the particular day or month (case doesn’t matter). Ranges or lists of names are not allowed.
For more information on the Unix and Linux crontab system, here are two links to local copies of the CentOS Linux crontab man pages (i.e., crontab help/support documentation):
Post new comment