Crontab

From Logicalwebhost-Wiki

Jump to: navigation, search

Crontab Reference Uncategorized — Ben Wong on October 14, 2006 at 4:02 pm A crontab task consists of four date/time fields and a command field. Every minute cron checks all crontabs for a match between the current date/time and their tasks. If there’s a match, the command is executed. The system crontab has an additional field “User” that tells cron with which user id the command should be executed.

 The fields are:
 Min       minute of execution, 0-59
 Hour      hour of execution, 0-23
 Mday      day of month of execution, 1-31
 Month     month of execution, 1-12 (or names)
 Wday      day of week of execution, 1-7 (1 = monday, 7 = sunday, or names)
 Command   Anything that can be launched from the command line

Possible values:

 *       matches all values, e.g. a * in month means: "every month"
 x-y     matches the range x to y, e.g.
 2-4 in Mday means "on the 2nd, 3rd, and 4th of the month"
 x/n     in range x with frequency n, e.g. */2 in Hour means "every other hour"

Months can be names: jan, Feb, mAr (case insensitive). (use 3 chars)
Weekdays can be names, e.g. sun, Mon, tUe. (use 3 chars, no case)

Special Strings

These can be used to replace the 5 time values.

 string          meaning
 ------          -------
 @reboot         Run once, at startup.
 @yearly         Run once a year, "0 0 1 1 *".
 @annually       (same as @yearly)
 @monthly        Run once a month, "0 0 1 * *".
 @weekly         Run once a week, "0 0 * * 0".
 @daily          Run once a day, "0 0 * * *".
 @midnight       (same as @daily)
 @hourly         Run once an hour, "0 * * * *".

Emailing Cron Output:

 MAILTO="recipient@domain.com"
 MAILTO=""  <- will send no email

Examples:

 # Run drupal cron every 15 minutes..
 */15 * * * * /usr/local/bin/wget -q -O /dev/null http://www.mostlygeek.com/cron.php
 # Update ports/sources and ports db. (2 commands, one cron line)
 34 3 * * * cvsup -g -L 0 /root/supfile ; portsdb -Uu
 # run nightly yum update and log results to /var/log/messages
 32 1 * * * yum -y update > /var/log/messages
 32 1 * * * yum -y update > /dev/null 2>&1
 # run /var/www/update.sh script every 10 mins
 */10 * * * * /var/www/update-data.sh > /dev/null

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

 >/dev/null 2>&1
Personal tools