301: How to run a cron job
Click here to watch a video tutorial
You can use cPanel's Cron Job feature to run Unix commands and/or automate the execution of your PHP, Perl, or Python Scripts. To create a Cron Job, you would first log in to your cPanel under "Cron Jobs" then select either "Standard" or "Advanced." You can also specify an email address that the Cron daemon will send the job's results to.
Set up the Crontab
You can do this easily in Standard Mode, but if you are using advanced you'll need to pay attention to time fields:
Specify when the cron job will run. The order is:
[minute] [hour] [day] [month] [weekday] [command]
41 04 * * 1 /my/script -v
This will run every morning at 4:41AM. The * is a wild card, meaning "every day/month, etc" For example; 41 04 * * 1 = every 41 minutes of every 4th hour of ever day of every weekday of month. Weekday is every day of the week including the weekends. Many customers have thought that weekdays are only Monday - Friday, instead of interpreting it as Monday - Sunday.
When setting the time, it is also good to set the cron to run at an odd minute, instead of the top (example: 12:00) or bottom (example: 12:30) of the hour. The example above runs at 4:41. The reasoning behind this is that most people set their crons to run at either the top or bottom of the hour. If everyone runs their crons at the same time, this can cause the crons to run slow and even slow the overall server down for regular website traffic. Setting it at an odd time ensures better performance of the script.
Specify the command to run
The command will have two parts:
[program to execute (perl/pyth./php)] [switches] [script]
The program to run will specify the type of script you are running and will either be:
The script will need to be called on its direct path as it is located on our server, so it will be something similar to: /home/userna5/public_html/path/to/script, with "userna5" being your username.
perl/cgi scripts should be in your cgi-bin, with permissions of 755 Please read our article on file permissions for more information.
- To run a PHP script: php -q /home/usern5/public_html/scripts/testrun.php
- For Python scripts: python /home/usern5/public_html/path/to/script
- For Perl/CGI scripts: /home/usern5/public_html/cgi-bin/yourscript.pl
Using the User Agent String
The wget command is disabled on all the shared servers for security purposes. Most scripts that are run via wget can be used with the lynx or curl command. The new mod_security rules that were applied with the latest php updates will prevent lynx and curl from working if a user agent is not set. To set the user agent, you can use the following command:
- curl --user-agent YOUR_STRING (URL)
- lynx -dump -useragent=YOUR_STRING (URL)
Your full cron job command would end up looking like this:
/usr/bin/curl --user-agent cPanel-Cron http://example.com/cron.php
In this case we defined our curl User-Agent to be cPanel-Cron, you can set it to be whatever you'd like, so long as it is defined in your cron command as something.
Cron Job Troubleshooting
If you need further assistance please feel free to ask a question on our support center website about your cron job issues.
We value your feedback!
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.
2014-04-16 10:11 pm
how to write this command in curl i try to work out but keep getting error
/usr/bin/wget -O - -q -t 1 http://www.fusionunlocking.com/includes/cron.php?action=fusion10
2014-04-17 8:24 am
It looks like you're simply trying to reach a page using wget. To do so using cURL, run something like this:
/usr/bin/curl --user-agent cPanel-Cron http://www.fusionunlocking.com/includes/cron.php?action=fusion10
2014-04-17 10:40 am
when i add this command im getting lots email
Cron <fusion37@biz150> /usr/bin/curl --user-agent cPanel-Cron http://www.fusionunlocking.com/includes/cron.php?action=fusion7
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
how to stop please
2014-04-17 12:25 pm
I reviewed your account and it's showing that you spoke with live support a short while regarding this issue. When I reviewed your cron jobs, you do have it running 3 different times, so based on whatever you have running in cron.php, it may return a lot of email. It appears to be a third party application that you're using in the cron job, so you may need to confer with their support or documentation in order to configure it differently if you're getting an excessive amount of email.
If you still require further assistance, please provide us more information on the issue and we would be happy to review it to see if we could be of any help.
2014-04-18 7:44 am
i have contact to my coder they reply this
just ask your hosting for antiviral command "/usr/bin/wget -O - -q -t 1 " can work with there hosting server .
2014-04-18 7:49 am
cURL can accomplish the same tasks as wget is able to so I am unsure as to why they are they insist on using that solution. If you are on a VPS or dedicated server, you may use wget, but if you are on shared hosting (Launch, Power, Pro), you wget is not an available option. On shared hosting, however, cURL may be used instead.
2014-04-18 8:02 am
/usr/bin/curl --user-agent cPanel-Cron http://www.fusionunlocking.com/includes/cron.php?action=fusion5
i have this commad work fine only problem yestrday one or support member stop email but now im getting again
i want to make cron job run quite no emails
2014-04-18 8:43 am
To do so, set the command to:
/usr/bin/curl --user-agent cPanel-Cron http://www.fusionunlocking.com/includes/cron.php?action=fusion5 > /dev/null 2>&1
Post a Comment
Do you want to publish a tutorial to our support center?