Cron Tutorial
Solution What is cron?

"A function" that executes commands at specified times and dates, according to instructions in the special file, so-called crontab file.

Can I run cron job with you?

Mostly for sure. However, please take note of our Terms of Service in relation to cron jobs:

"No cron job may run more than once every two hours."

If your crontab meets these specifications, you may still run it.

How can I use cron?

To use cron, you must first set up a file of cron entries. This file can actually be placed anywhere in your account you like, and have any name you want. It should contain one entry for each action you want taken.

A cron entry looks similar to the following:

30 3 * * * /usr/home/username/script.pl

In this case, the script "script.pl" would be run nightly at 3:30 AM.

"/usr/home/username/script.pl" is the full path to the script/program you would like cron to run. You can also use regular UNIX commands here if you like, using full paths to programs. For instance, you could have

30 3 * * * /bin/rm /usr/home/username/temp/*

to remove all files from some temporary directory you might have each night at 3:30 AM, as in the earlier example.

The "30 3 * * *" requires a bit more explaining. The time a cron command is executed is controlled by the 5 numbers that precede the cron directive.

The first number is the minutes after the hour (0-59).
The second is the hour of the day (0-23, with 0 being 12 AM).
The third number is the day of the month (1-31).
The fourth is the month of the year (1-12).
The fifth is the day of the week (0-6, with 0=Sunday and 6=Saturday, etc).
A * in place of any of the values matches all possibilities (for instance, in the given example the script runs every day because the *'s for day of the month, day of the week, and month of the year match all values).

Multiple values are separated by commas. For instance, you might start with 15 1,3,5 * * * to run a script every day at 1:15, 3:15, and 5:15.

Once you have your cron directive file (say, cron.file) in your account, you must connect via SSH (secure telnet) and issue the command.

crontab cron.file

using the name you gave the file. (Note that you must be in the same directory as the cron file at the time.) After this, your cron should be activated. If the programs running via cron generate errors, the cron daemon will e-mail them to your account. If at any time you would like to change your cron jobs, just edit your file, and rerun the crontab command as shown above.

Further cron resources:

Cron generator:
http://www.webmaster-toolkit.com/cron-generator.shtml

Tutorial:
http://aplawrence.com/Basics/bbcronbasics.html


Article Details
Article ID: 138
Created On: 25 Jan 2008 01:04 AM

 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
 
 Search
 Article Options