CRON – Automatically Run Jobs on Your Website

CRON is a function in Unix and Linux operating systems which allows you to schedule a job and the job will run at the date and time scheduled until you delete the CRON statement.

Initially, you may consider this to be too technical for you, but not so if you will carefully read this article. It is a function of which you should be aware. Even if you do not need it now, remember about CRON for the day you will need it.

Apache server includes this function and it is easy to use with the graphical interface.

The format for CRON is “CRON * * * * * Command to execute”

Each asterisk represents a field in the command and can contain the following values. If you do not want to specify a value for that particular field, leave the asterisk in that position in the CRON statement line. Each of the five fields is separated by white space.

Here are the values that each field (left to right) can have other than the asterisk:

Field ——– Value —– Description
minute —– 00-59 ——exact minute the cron executes
hour ——– 00-23 —— hour of the day the cron executes(0 =midnight)
day ——— 01-31 —— day of the month the cron executes
month —— 01-12 —— month of the year the cron executes
weekday — 00-06 —– ay of the week the cron executes(Sunday = 0, Monday = 1, Tuesday = 2, etc)
command —varies —— sequence of commands to execute

What prompted the need for the CRON on our site was our use of the software package that required that we copy the ClickBank master file into a file on the Boomer-eZine website periodically so our copy is kept current with the ClickBank master.

Since we get busy and forget to do this weekly, a method to have our web host perform this automatically was the answer.

The CRON function is very flexible and can be set to run on almost any time frequency you can imagine.

If you specify a minute in the first field and an hour (24 hour clock) in the second field and leave all the other fields as asterisks, the specified program will run on that hour and minute every day. If you want the program to run twice a day at 10 and 11 AM, you can write the CRON as:

CRON 0 10,11 * * * Command to execute

With the proper combinations, you can set up a job to run automatically on almost any schedule that you can imagine.

Let’s try a few. Write a CRON to execute on every Sunday at midnight.

If you got “0 0 * * 0 Command to execute”, then you are right. The zero in the first position is on the hour. The zero in the second position is midnight. The zero in the fifth position (day of the week) is Sunday. This is what we used for our CRON settings for the CD AD Box update.

Set up a CRON to run once per year on the last day of the year at midnight.

CRON 0 0 31 12 * Command to execute

If you have a graphical interface on your web server, it is easy to enter the CRON information
Sometimes the CRON function is difficult to find in your control panel. If you have difficulty finding it, send an email to the support group for your web host and ask if this is available and if so, where is it located.

As I said earlier, you may not need this right now, but remember it for when it will come in handy for you. It can greatly simplify the work of managing your website.

Copyright 2006 John Howe, Inc.