Saturday, May 05, 2007

Creating a Crontab

What is Crontab ?

Crontab is a program that allows users to create jobs that will run at a given time.
Each individual user has their own crontab and the entire system has a crontab that can only be modified by those with root access.

If you are adding a crontab for an individual user you must sign on as that user first. (ex. su userid)
The syntax of this file is very rigid.

There are six fields to a file, each separated by a space.
The first five fields specify exactly when the command is to be run; the sixth field is the command itself.

The first five fields are:
Formatminute hour day month weekday command Minute - Minutes after the hour (0-59).
Hour - 24-hour format (0-23).
Day - Day of the month (1-31).
Month - Month of the year (1-12).
Weekday - Day of the week. (0-6; the 0 refers to Sunday).

Asterisks (*) specify when commands are to be run in every instance of the value of the field.
For instance, an asterisk in the Month field would mean that the command should be run every month.

In addition, multiple events can be scheduled within a field by separating all instances with commas - with no space between.
Optionscrontab -eEdits the current crontab or creates a new one. *
crontab -lLists the contents of the crontab file.
crontab -r Removes the crontab file.

Creating a Crontab for use with AccessWatch You must first sign on as the individual user you are adding the crontab for.
Do not create crontab while you are signed on as "su" under root or you will change the root crontab.
After you sign on as root su as individual user. su userid ex. su nercols
Change editor to Joe from VI:
EDITOR=vi
export EDITOR
Create the crontab from the command line:

crontab -e
Insert the following lines and the save the file (Ctrl-kx):
30 23 * * * /home/userid/www/aw/aw-parser.pl -d45 23 * * * /home/userid/www/aw/aw-report.pl
AccessWatch will run against the log files in their home directory every evening at 11:30 and then generate a report at 11:45 p.m..
Type man crontab for more detailed information.
If you don't want to set up a crontab just run the by hand when you want a report.

./aw-parser.pl
./aw-report.pl