Back to Technical Support

How To Use Cron


Cron is a tool to allows 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:

  • crontab -e - Edit your crontab file, or create one if it doesn't already exist.
  • crontab -l - Display your crontab file.
  • crontab -r - Remove your crontab file.

Creating/Editing Cron On Your VPS

  1. Connect to your account through SSH.
  2. Type edit cron -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:

  • The first number is the minute of the hour for the command to run on (0 - 59).
  • The second number is the hour of the day for the command to run on (0 - 23)).
  • The third number is the day of the month for the command to run on (1 - 31).
  • The fourth number is the month of the year for the command to run on (1 - 12).
  • The fifth number is the day of the week for the command to run on (0 - 6 where Sunday=0).

Below is an example of a cron entry:

#MinuteHourDayMnthMonthDayWeekCommand
#---------------------------------------------------------------------
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 no other rules are 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 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:

#MinuteHourDayMnthMonthDayWeekCommand
#---------------------------------------------------------------------
0 , 5, 10*/2***/home/accountname/filetorun

 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.


Related Articles

How To Backup Your Website In WordPress
How To Clean Your Site In WordPress
How To Configure Miva Store Utility
How To Find Your Site Manager Account's IP Address
How To Install CGI Software

Can’t Find what you need?

No worries, Our experts are here to help.