RapidFX

CRONTAB

3/7/2007 3:17:44 PM



crontab -e user
man crontab
------------------------

0 * * * * /path/script.cgi
0 0 * * * /path/script2.cgi


A crontab file can have any number of commands.
One command per line:

[ 0 * * * * * /path/script.cgi ] is COMMAND ONE

and

[ 0 0 * * * /path/script2.cgi ] is COMMAND TWO

ONE COMMAND PER LINE.

Each line or command is scheduled to run at a specific time.
The first 5 fields set the time the command will run.

0 * * * * is the SCHEDULE for COMMAND ONE [ /path/script.cgi]

0 0 * * * is the SCHEDULE for COMMAND TWO [ /path/script2.cgi]

There are FIVE fields to the SCHEDULE

MINUTE(0-59) HOUR(0-23) DAYOFMONTH(1-31) MONTHOFYEAR(1-12) DAYOFWEEK(0-6)

0 = Sunday

The ASTERISK (*) is a WILDCARD meaning it will match any value.

The first command of the example:

0 * * * * /path/script.cgi

Execute script located at /path/script.cgi whenever the clock is equal to 0 minutes
ANY DAY, ANY HOUR, ANY DAY OF THE MONTH, ANY DAY OF THE WEEK
The file script.cgi will run ONCE PER HOUR EXACTLY ON THE HOUR regardless of what day or hour.

The second command of the example:

0 0 * * * /path/script2.cgi

This runs whenever the internal clock hits ZERO (0) Minutes, but instead of running
once per HOUR it will run once per DAY.
This example runs once per DAY at MIDNIGHT local server time.
We have set the HOUR to zero, so BOTH the MINUTES and HOUR must be equal to zero before
crontab will execute: /path/script2.cgi

------------------------------

This example sets a crontab to run every Sunday at 5:45 AM.

MIN = 45
HOUR = 5 (military time 0-24)
DAYOFMONTH = * (any day)
MONTHOFYEAR = * (any year)
DAYOFWEEK = 1 (sun=0, mon=1, tue=2)

The crontab would be:

45 5 * * 0 /path/script.cgi

------------------------------

EXAMPLE 3

MAILTO=""
0 5 * * * /bin/cat /var/log/httpd-access.log | grep text > /usr/home/user/public_html/file.txt && chmod 755 /usr/home/user/public_html/file.txt && chown user:group /usr/home/user/public_html/file.txt

The mailto command sets the email address to send reports to.
You can also choose to not have output sent, in which case, set the following:
MAILTO="user@example.com"
OR
MAILTO=""

(MAILTO is case sensitive)