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:"

cron1

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.



IMPORTANT:

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:

  • php 
  • python
  • perl

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)

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Help Center:
Email Address
Optional, but our team may contact you for more information.
Did you find this article helpful?

Comments

2013-07-14 10:57 pm
I have a script to run that has arguments that need to be passed to it, is there a solution for that?
7,078 Points
2013-07-15 10:17 am
Hello blaincar,

I'm not sure exactly what you are trying to accomplish, but I found a forum post via Google search on How to Pass a variable to a php cron job. I hope this helps get you going in the right direction.

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
1,122 Points
2013-09-16 4:38 pm
JeffMa
Staff
Hello blaincar,

Yes, it can. You need to put double quotes around the URL parameter of the curl command, otherwise the operating system tries to interrupt the HTML parameter as if it is a cURL parameter.

So the example in the article above should be:
curl -A "Mozilla 4.0" “http://mydomain.com/myscript.php&myparameter”

Working example to run the WordPress ‘WP-Cron Control’ plugin:
curl -A "Chrome 30.0" --silent "http://www.domain.com/wp-cron.php?doing_wp_cron&62647ba73f6dd22c3be278c1cc5c027a" > /dev/null 2>&1

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

Update to SSL Certificates - Certificate Warnings
1969-12-31 11:00 am EST
Hits: 696

Related Questions

Here are a few questions related to this article that our customers have asked:
Would you like to ask a question about this page? If so, click the button below!

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.