How can I enable cronjobs on my dedicated server?

This article applies to 123 Reg Linux Dedicated Servers.

This article explains how to configure scheduled tasks – also known as cronjobs – on your dedicated server.

Cron is a utility that allows tasks to be automatically run in the background at regular intervals. Similar to Scheduled Tasks on Windows machines, a crontask or cronjob allows a user to define a consistent schedule to run a script or command, for example, to take a weekly backup of a website.

Basic Commands

When logged in to the SSH terminal for your dedicated server, the crontab command allows viewing or editing of the file from where your cronjobs will run.

crontab -e – Run this command to edit your crontab file, or create one if it does not already exist.

crontab -l – Run this command to display your current crontab file.

Cron Syntax

A crontab file has five fields for specifying day date and time, followed by the command to be run at that interval as demonstrated below.

* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (0 – 6) (Sunday=0)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)

For example, if you wanted to delete files from /home/username/tmp each day at 18:30, you should add the cronjob in the following format.

30 18 * * * rm /home/username/tmp/*

Executing PHP scripts using Cron

A number of our users require their PHP scripts to be executed within a schedule. This too can be achieved using a cronjob however you will need to specify the PHP script engine that should be used to execute the script.

For example, if you wanted to run your PHP script every 10 minutes of every day, you should add the cronjob in the following format.

*/10 * * * * /usr/bin/php5 /path/to/your/script.php

Please note: Cronjobs are configured at the user’s own risk. If you are in any doubt with regards to configuring cronjobs on your dedicated server, please contact the 123 Reg support team.