
The Unix operating system we use offers a feature called "cron jobs". A "cron job" is a task that runs a script at regular intervals on your Web server.
Advanced users can use cron jobs with any of our Web hosting plans. On this page:
To set up a cron job, you'll make a telnet or SSH connection to your Web server and type this command:
crontab -e
By default, the "vim" text editor is used when editing cron jobs. Some users quite understandably find vim to be confusing; you may wish to use a simpler editor such as pico, which you can do by typing this before using "crontab -e":
export EDITOR=pico; crontab -e
When editing cron jobs in pico, you can save your changes by pressing CTRL-X to exit, then pressing Y to save the changes and allowing it to use the file name the program suggests.
A full description of how to use cron jobs is beyond the scope of this page (and in most cases, any script that instructs you to set up a cron job will tell you exactly how to do it) — but if you really want the gory details, type these two commands after logging in:
man 1 crontab man 5 crontab
Many sites on the Internet have tutorial pages explaining how to use cron jobs, including:
Searching for "crontab" in your favorite search engine will turn up many more pages if you have questions.
Remember that cron jobs run scripts on the server's disk, just as if you'd typed the cron command in your home directory. Cron jobs don't load Web pages (at least not without extra effort).
Occasionally, it may be necessary for a cron job to load a Web page. For example, let's say you have a PHP 5 script that runs when you load this Web page:
http://www.example.com/cron.php
If you want to run that script in a cron job at 20 minutes past every hour, one way to do it is to figure out which command you would type on the command line (knowing the disk-based path to your Web directory or home directory will help) and make the cron entry be:
20 * * * * cd /var/www/html/ex/example.com; /usr/bin/php5 cron.php
If you really need to actually load the Web page from your cron job, use the /usr/bin/wget program in your cron job entry, like this:
20 * * * * /usr/bin/wget --quiet -O - 'http://www.example.com/cron.php'
(Hint: Each cron job entry must be entered entirely on a single line. Be sure you don't enter any carriage returns between parts of the line.)
If a cron job displays any text when it runs, that text will be e-mailed to the administrative contact we have on file for the account each time the cron job runs.
If you want the text sent to a different address, put this line before any other lines in your crontab file:
MAILTO = address@example.com
(Specifying the actual address you want instead of "address@example.com", of course.)
It's also possible to completely suppress the mailing of output from a cron job with this line (again, before any other lines):
MAILTO = ""
However, we don't recommend doing this because if your script stops working properly and starts emitting error messages, you'll never see them. Instead, filter the cron messages into a separate folder of your mail program and delete them a few days later: that way, if something goes wrong, you can look back over the last few cron messages and see what happened.
To completely disable all your cron jobs, make a telnet or SSH connection to your Web server and use this command:
crontab -r
(If you have multiple cron jobs — that is, you have multiple lines in your crontab — and you just want to remove one of the jobs, use "crontab -e" instead and delete the appropriate line.)
We have a few commonsense policies about cron jobs:
We're often asked if it's possible to use cron jobs to make MySQL database backups. The good news is that you don't need to: we already make nightly backups of all MySQL databases.
(That said, note that the MySQL backups just save a copy of your data on our servers. It's wise to also copy those backup files to your own computer, but you can't usually automate that with cron jobs on our servers — you'd need the equivalent of a cron job on your own computer.)