If you are a webmaster that runs a blog, website portal, company website or Internet application service you will want to automate repetitive daily tasks. If you are using a shared hosting provider that has cPanel installed, you can do this by creating a cron job.
What is a cron job?
A cron job is a Linux program that lets users schedule commands and shell scripts to be executed at regular intervals.
What kind of applications use a cron job?
If your site uses the Drupal CMS, there maybe modules that need to be invoked to do periodic tasks. One example is if you are using the search module. Whenever you create a new article, blog post, story or new content node, that node does not get indexed by the search engine immediately. Instead, Drupal's cron.php file must be invoked to iterate through all modules asking them to call their cron handlers.
If you run aTextpattern or Joomla site, you may be familiar with the SimplePie plug-in that grabs a RSS feed and renders it on a page.
Other applications that can use cron jobs are email servers, backup programs, and generating web server log statistics. The possibilities are endless.
How to setup a cron job in cPanel
On a shared environment, you do not have administrator access to the server you are hosting on. Most web hosting providers like Hostgator will have a user friendly administration application like cPanel.
- Look in your cPanel administration page for a cron job icon or link.
- Click on it and you will be taken to a page that allows you to choose a standard or advanced advanced job.
- Choose standard mode
You will then be taken to a screen similar to this:

Now at this point you need to know the name of the program and where it it is stored in the file system. In a shared hosting environment, you will not be able to run just any program on the web server as that would be a security risk.
It is best to contact your hosting provider and what programs you can execute. Most blogging software (Wordpress, Textpattern) and content management systems (Drupal, Joomla) are written using the PHP programming language. Typically, you will want to execute PHP scripts that you or the software has created to do automated tasks.
For example, if you are using Drupal and need to execute the cron.php file you would setup your standard cron job to do something like this on Hostgator:

The command we are executing is:
wget -q -O - http://www.site.com/cron.php >/dev/null 2>&1cron.php is to be executed every month (Jan-Dec), every weekday (Sun-Sat), and every day every other hour. It is wise to use your best judgement when setting up your cron jobs. Over specifying could get your hosting account terminated as you would be taking up too much CPU time.
Next, enter in your email address so that you can be informed when the cron jobs are executed. This is a useful feature in cPanel to inform you if there are any problems.
Now that your cron job is scheduled, click on the 'Save crontab' button and you are done.
Update:
There seems to be a lot of different ways to run a cron job from cPanel and some work and some don't. Here is a list of other things you can try if you are having problems:
A) /usr/bin/php -f /home/yourusername/public_html/cron.php
B) /usr/bin/lynx -source http://www.site.com/cron.php > /dev/null 2>&1
C) get http://www.site.com/cron.php- SiteAdmin's blog
- Login or register to post comments

Del.icio.us
Digg
Technorati