Cron Jobs

What is a Cron Job?

A cron is a time based scheduler which runs a command or script on your server automatically. Cron jobs are used for scheduling jobs (commands or scripts) to run periodically at fixed times, dates, or intervals.

Can I use it?

Our servers do support the use of cron jobs. Please take note that cron jobs are a Unix based utility, thus you can only run cron jobs on Linux servers only.

How do I set up a cron job?

The cron job function is placed under the FTP Manager section on the control panel. To access this screen click on the FTP Manager icon.

cron1

Once the new screen loads, you will see the Crontab line at the very bottom of the list of Parameters. From here we can click the Off button to turn the Crontab ON.

cron2

After clicking on the Off button, your screen should refresh and the button will not show ON. This option is now active for all domains on your account. To start creating your cron jobs, click the Edit icon next to ON.

cron3

Before adding any content to the blank fields, ensure the email address in the Mail-To field is correct. This should be an email address that you check often. The email address that is used to log into your account is set here by default. The email address here is used for sending reports to, regarding the commands that are run on the server.

cron4

Now that the Mail-To address has been set, commands can be set up to execute at the times you want. The following fields are open to fill in:

- Minute
- Hour
- Day Of Month
- Month
- Day of week
- Command

The last field is the command field where your script will be located to execute. If you run this script in the domain folder, you will put the entire script path in this field.  Here is an example of a script path: /hsphere/local/home/FTP_username/domain.com/script.php. It’s possible that you may want to run PHP scripts in your Crontab. To do this using the following commands to start the cron:

For PHP 5.2
/hsphere/shared/php5/bin/php-cgi -f ~/domain.com/example.php -c ~/domain.com/cgi-bin/php.ini

For PHP 5.3
/hsphere/shared/php53/bin/php-cgi -f ~/domain.com/example.php -c ~/domain.com/cgi-bin/php.ini

cron5

The rest of the fields set the exact date and time the script will run or be executed. The values that can be put into each field are in the next image.

cron6

If you want to execute your cron job every minute, hour, day, and month, simply place an * in the empty field. For example, you may have a script you wish to run every 20 minutes each Sunday in June. What should be entered into the empty fields should look something like this:

cron7

To run once a year at midnight on January 1st enter 0, 0, 1, 1, * (respectively) into the blank fields.

To have a script run once a month at midnight on the first of the month enter 0, 0, 1, *, *.

For scripts running once a week at midnight on Sundays 0, 0, *, *, 0

Run a script once a day at midnight 0, 0, *, *, *

Enter 0, *, *, *, * to run once an hour and the beginning of every hour

What commands can I use?

Any and all scripts that can be created can be executed using a cron job. In addition to this, you may check the account quota which shows your web disk space and the amount of files in the account. Here is a little more information on these commands that can be used:

To receive information about the account quota use quota -s. As stated above, this will send information about the account’s disk space usage to the email specified in the cron tab. Checking the size of any folder can be returned using, du -h yourdomain.com. Keep in mind that by default a cron will send an email to the specified mailbox in the crontab, when the cron job executes. If this is an unwanted function you may insert the following code at the end of the cron script, >/dev/null 2>&1.

That’s it! Click on Submit Query to start running your newly created cron job(s).

Was this article helpful?

Yes (103)
No (2)

We're sorry you didn't find this article very helpful. Please help us improve it by leaving your feedback below.

Error