Using Cron

Cron is a tool to allow you to run a program on a particular schedule. This is useful for running a log processor every day, or a monthly compilation of data on your site, or any number of other purposes.

Cron Commands

The following cron commands can be entered at the command line to manage your cron file:

Creating/Editing Cron On Your VPS

  1. Connect to your account through SSH.
  2. Type editcron -e at the command line.
  3. Enter the information for your cron (see cron syntax below for examples).

Cron Syntax/Usage

A cron entry has 5 time periods for which you can define when it should run:

Below is an example of a cron entry:

#Minute Hour DayMnth Month DayWeek Command
#------ ------- ------- ------- ------- -----------------------------------
0 * * * * /home/accountname/filetorun

The first two lines above are just comments and not read because of the '#' sign at the beginning of the line. The third line is the actual command that will be run (and the times when it will be run). In this case, the script will be run at the top of the hour, every hour (1:00am, 2:00am, etc).

Any time an asterisk (*) is used, the cron will run whenever it matches and there are no other rules limiting its running. It is never recommended to use an '*' in the minute field because the script will run constantly until the time set on the other time fields (but if all other fields are '*'s as well, then the script will never stop running).

If you have a situation where you need a script multiple times during a given time period (multiple minutes, hours, etc) then you can specify a list of times separated by commas, or if it is a regular interval, you can specify an '*' then a '/' then the interval you want to run at. For example:

#Minute Hour DayMnth Month DayWeek Command
#------ ------- ------- ------- ------- -----------------------------------
0 , 5, 10 */2 * * * /home/accountname/filetorun

NOTE: The program you are running must have permissions of 755 (rwxr-xr-x). The cron file recognizes both tabs and spaces as separators between fields. There is no set length for each section, so once you have a space or a tab, it is assumed that you are moving on to the next field. Multiple spaces or tabs together are considered as one.