How to set up automated jobs for your use with your Linux hosting account.
What are Crontabs?
You may have seen or heard the term Crontab being used around the internet. A Crontab (Short for Cron Table) is a file which provides a list of scheduled Cron tab entries to be ran at specific times. In basic terms: It’s a way to schedule an automated task, such as running a report script on your website at a specific time every day.
Creating a scheduled job
Scheduled jobs (Crontabs) are managed within the Hosting Control Panel. Follow the steps below.
-
- Navigate to FTP/User Account > FTP User
-
- Turn on Crontab by clicking the red square (If not already turned on).
-
- Click on the edit icon.
-
- Create a Scheduled Job
This is the screen you will be presented with.
Minutes: This is usually a number between 0 and 59
Hours: Usually a number between 0 and 23, Can also be * to represent hourly.
Day of Month: A number between 1 and 31 or * to represent daily.
Month: Number between 1 and 12 or * to be ran every month.
Day of the week: A number between 1 and 7, can be * to represent every day of the week.
An example of what you could use below:
This will run the command at 00:00 every day of every month. If you only wanted to run on Mondays, you would change Day of the Week to be 1. If you wanted Monday, Wednesday and Friday. You would change Day of the Week to be 1,3,5.
Modifiers: If you wanted to run a script every 30 minutes, you would set the Minute to be: */30 – Similarly for every 6 hours, would be */6 in the Hour section.
Stopping Email: To prevent email from sending after each cron, simply add the following to the end of your command.
/dev/null 2>&1
Commonly used file locations
If you’re using a Crontab and would like to reference PHP, you can use the following file locations, depending on the version of PHP required to run the script.
PHP
-
-
- /hsphere/shared/php56/bin/php
- /hsphere/shared/php71/bin/php
- /hsphere/shared/php72/bin/php
-
Perl
-
-
- /usr/bin/perl
-
Python
-
-
- /usr/bin/python
-
Curl/Wget
-
-
- /usr/bin/curl
- /usr/bin/wget
-
If you intend to use them as if they were in the web browser then wget should be used, available at /usr/share/wget
e.g.
/usr/share/wget -v --delete-after http://domain.com/path/to/script.php
Some may ask what does -v mean, it stands for verbose. What this option will do is give you an output on what is happening and you can see in real time how the task is doing.
PHP CLI
Using the above file locations you can invoke PHP CLI to automate the running of PHP scripts on the server. However to use PHP-CLI you need to request SSH access, please see this guide.
PHP CLI command example usages:
/hsphere/shared/php55/bin/php-cli /hsphere/local/home/USERNAME/MyPhpScript.php
The above example uses PHP 5.5. An example using PHP 7.2 would be:
/hsphere/shared/php72/bin/php-cli /hsphere/local/home/USERNAME/MyPhpScript.php
Classification: Public
Last saved: 2021/11/11 at 14:22 by Jamie