You can use cPanel's Cron Job feature to run Unix commands and also automate the execution of your PHP, Perl, or Python Scripts. To create a Cron Job, first log into your cPanel and select "Cron jobs:"
Add a New Cron Job
Cron jobs use the following time field sequence:
[minute] [hour] [day] [month] [weekday] [command]
48 09 * * * /my/script -v
This will run every morning at 9:48 AM. The * is a wild card, meaning "every day/month, etc" For example; 48 09 * * * = every 48 minutes of every 9th hour of every day of of the month. Just to clarify, the setting for "Weekday" should be interpreted as day of the week, including Saturday and Sunday. Many people think of weekday as just Monday through Friday, but when referring to cron job settings, it actually means every day of the week.
It is suggested that Cron Jobs not be scheduled at the top or bottom of the hour. Remember that you are not the only user on the server who may be using a cron job. If all the cron jobs were scheduled at the same time, the server performance would be slowed when it tries to execute all of the scripts. So, for example, the best times to set a cron job to run may be at an odd minute such as the example above. It is set to run at 9:48 every morning. Help keep server performance at an optimum level by setting the cron job execution at an odd time.
Specify the command to run the php script
The command should have two parts:
[program to run (perl/pyth./php)] [switches] [script]
The program to run will specify the type of script you are executing, and will either be:
The script will need to be connected directly to its location on our server, so it will be something similar to: /home/username/public_html/path/to/script, with "username" being your username.
- To run a PHP script: php -q /home/username/public_html/scripts/testrun.php
- For Python scripts: python /home/username/public_html/path/to/script
- For Perl/CGI scripts: /home/username/public_html/cgi-bin/yourscript.pl
Alternative to wget command
Most scripts that are run through wget can be ran through lynx or curl commands, which are allowed in Cron Jobs. Be sure to set the user agent in any lynx or curl commands you run. If the user agent isn't set, mod_security rules on the server will prevent the commands from running. For example:
curl -A -s useragent (URL)
curl -A "Mozilla 4.0" http://mydomain.com/myscript.php
lynx -dump -useragent (URL)