OS X and many flavors of *nix come with Crontab, an excellent program to run unattended jobs. I currently use crontab to run AWStats. I also have several scripts that I run nightly. This short tutorial should allow you to set up your own Crontab jobs.

Create a script you wish to run. For this example, I am going to use the awstats.pl script to update my stats. The command to run the update is:

/path/to/awstats.pl -update -config=myconfig

2. Create a new crontab file for your user. This is accomplished by opening the Terminal.app, found in your Application/Utilities folder. Type the following into the terminal:

crontab -e

If you do not have a crontab file, one will be created for you and opened in vi.

3. Choose when you would like the job to run. Every job is a line in your crontab file. The first 5 arguments specify the time to run the job, and the 6th argument is the command to run.

Argument 1: Minute (0 – 59)
Argument 2: Hour (0 – 23)
Argument 3: Day of Month (1 – 31)
Argument 4: Month (1-12)
Argument 5: Day of Week (0 – 6) Sunday = 0
Argument 6: Command

So if I want to update my stats every 30 minutes, my entry in my crontab file will look like this:

*/30 * * * * /path/to/awstats.pl -update -config=myconfig

Save the file, and crontab should report:

crontab: installing new crontab

To see a list of your crontabs, run this command:

crontab -l

That’s it! Crontab will now update the stats every half hour. It also will generate an email to your local user account to let you know it did its job. Most times your local user account’s mailbox will not be where you want to be notified. To forward your email, create a file in your home directory called .forward. In the file put the email address where you would like the notification to be sent to.