crontabs

Crontabs are used to run scripts (cron jobs) periodically on the server.

IMPORTANT NOTICE

Please use this service with care as excessive use will degrade server performance. You can only run shell or perl scripts in this way and we will delete without notice any scripts that use excessive amounts of CPU time or cause other problems.

.crontab files

Crontabs are installed automatically by the server, just put your crontab in a file called “.crontab” in the root of your FTP space. The .crontab file should look something like:

0 * * * *    /path/to/some/program
<MUST CONTAIN ONE BLANK LINE AT END OF FILE>

Once installed this will run the program every hour. Please ensure you have a blank line at the end of your crontab file and that you upload it in FTP Text mode.

Running PHP scripts from a crontab

If you want to run PHP scripts you will need to use Curl to call them, ie:

*/5 * * * *  /usr/bin/curl -s http://www.mysite.co.uk/somescript.php
<MUST CONTAIN ONE BLANK LINE AT END OF FILE>

You must use the www. prefix on the URL otherwise the server will not find the site. The ‘-s’ option tells Curl to handle the call silently otherwise the server will send you an email every time the script runs.

The crontab daemon will check for updates to your .crontab file every five minutes. This page has more info on the format of crontabs: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

Crontab field definitions

Field Meaning
1 Minute (0-59)
2 Hour (2-24)
3 Day of month (1-31)
4 Month (1-12, Jan, Feb, etc)
5 Day of week (0-6) 0 = Sunday, 1 = Monday etc.,
6 User that the command will run as
7 Command to execute

A field may be an asterisk (*), which always stands for “first-last”.

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an “hours” entry specifies execution at hours 8, 9, 10 and 11.

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: “1,2,5,9”, “0-4,8-12”.

Step values can be used in conjunction with ranges. Following a range with “/<number>” specifies skips of the number’s value through the range. For example, “0-23/2” can be used in the hours field to specify command execution every other hour. Steps are also permitted after an asterisk, so if you want to say “every two hours”, just use “*/2”.

Debugging problems

If you have problems or not sure your crontab is running then try inserting the line below to the top of your crontab file and inserting your email address. This should then email you everytime your crontab file runs and will include errors if there are any.

MAILTO="youremailaddress"

Caching Issues

Sometimes you may make changes to the .crontab file and these changes are not picked up by the server. In these cases we suggest you leave the file there but empty it completely for about 10 minutes and then re-edit and copy back the contents including the blank line at the end. The new details should then be picked up within about 5 minutes.