Cron on Ubuntu

Cron on Ubuntu

By sublet on Jul 6th, 2011 at 9:33 AM

One thing that is near and dear to all of us programmers are automated processes. Before, when I was using a hosted solution, I had a beautiful control panel that made it easy to add and remove cron jobs. Now, however, I am using a Amazon EC2 instance without a control panel. So, I needed to figure out how to make things work without a control panel, and it’s actually very easy.

After you get logged into your instance you type:

crontab -e

Then I enter the following and replace the PATH_TO_FILE with the URL I want to process.  (Ex. http://www.mydomain.com/automated_process.php)

* * * * * /usr/bin/wget -q -O /dev/null PATH_TO_FILE

Once you save the file it will update your main crontab and you are good to go!

One of the things you will have to do is install php5-cli.  “CLI” stands for Command Line interface, and its a way of using PHP in the system command line.

To quote directly from the PHP-CLI site, “PHP CLI is a short for PHP Command Line Interface. As the name implies, this is a way of using PHP in the system command line. Or by other words it is a way of running PHP Scripts that aren’t on a web server (such as Apache web server or Microsoft IIS). People usually treat PHP as web development, server side tool. However, PHP CLI applies all advantages of PHP to shell scripting allowing to create either service side supporting scripts or system application even with GUI! ”

So to install this, just enter the following:

sudo apt-get install php5-cli

Also another good resource to check out, is the Ubuntu site on Cron: https://help.ubuntu.com/community/CronHowto