Click here to watch a video tutorial

Navigation:

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:

  • php
  • Python

 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.

Continued Education in Course cPanel
You are viewing Section 4: 301: How to run a cron job
Section 3: How to find which users are attached to databases
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 this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Has anyone used CURL in a cron job?
Moodle cron job failing
Cron job is not running
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
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

Staff
8,375 Points
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

n/a Points
2014-04-17 9:51 am

thank you i will try

 

 

n/a Points
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

 

 

Staff
16,603 Points
2014-04-17 12:25 pm
Hello Umar,

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.

Regards,
Arnel C.
n/a Points
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 .

 

regards

Staff
8,375 Points
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.
n/a Points
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

 

Staff
8,375 Points
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

n/a Points
2014-04-18 9:35 am

Great that works spot on no more emails

 

 

thank you

n/a Points
2014-06-15 2:31 pm

Hi mate, need some help, how do I write thiswget --quiet http://example.com/sitemap.xml --output-document - | egrep -o "http://example.com[^<]+" | wget -q --delete-after -i -I have a website that is taking a lot of time to load, somebody suggested this solution.

Staff
8,375 Points
2014-06-16 9:32 am
Could you clarify what exactly you are trying to accomplish with this?
n/a Points
2014-06-16 9:50 am

The website is actually developed in drupal and it takes a lot of time to load, at least 10-15 seconds just to show the title and rest of the website is visible in around 30-40 seconds.Someone on drupal support had written that this command above helped him to and his website now loads within seconds. I have no idea what this command will do. I thought maybe you can help that's why I had mentioned my problem as well. 

Staff
8,375 Points
2014-06-16 10:15 am
The command you provided simply grabs your existing sitemap and places it into a file. Either the complete information is not here, or someone may be misleading you. To optimize your site, you will want to slim down any code that you have written, and enable things like browser caching to increase performance.
n/a Points
2014-06-30 3:20 pm

Hi. Can you assist me? I have been trying for days to setup a cron job with no success. I want to fetch this URL:

http://www.mywebsite.com/index.php?option=com_iproperty&view=property&format=eupdate

I am using godaddy.com cron job manager (Linux).

Thanks very much

Staff
9,968 Points
2014-06-30 4:08 pm
Hello Lascelles,

If you need to pass URL variables through a cron job, I'd recommend using curl and just put your URL inside of single quotes like this:

curl 'http://www.example.com/index.php?option=com_iproperty&view=property&format=eupdate'


If you are still having any issues, please let us know how the cron job request looks in your website's access logs when run.

- Jacob
n/a Points
2014-07-01 3:06 pm

Hello Jacob. Thank you for replying to my question. I have setup tests using both curl and wget.

In my email, for curl, I received : % Total % Received % Xferd Average Speed Time Time Time Current

Along with what looks like the entire page html source code.

The most recent access file, dated June 30, basically contains a repetition of the following, plus other miscellaneous info

[30/Jun/2014:00:00:24 -0700] "GET www.example.com/index.php??option=com_iproperty&format=raw

I am not sure where to go from here.

Staff
9,968 Points
2014-07-01 3:59 pm
Hello Lascelles,

Both curl and wget request pages just like a web-browser would, so you will see the status of the page being fetched, and get the resulting HTML back. If you're doing it from a cron job it will be sent to you in an email by default as well.

If you'd like to not see the output from either, simply suppress the output from either with:

curl --silent http://example.com


wget --quiet http://example.com


Then also turn off email notifications in your cron job by running it like this:

curl --silent http://example.com >/dev/null 2>&1


Please let us know if you had any other questions at all.

- Jacob
n/a Points
2014-07-01 5:30 pm

Hello Jacob. Thanks again.

I see some of what I posted has been filtered, so you did not see all the info I entered here.

Even though the cron test(s) appear to show progress, I still have one or two questions:

Firstly, the purpose of this cron is to enable visitors of my real estate website to: log in; save searches for listings not found; receive email notifications as soon as a listing matching their saved criteria is found.

Now, I have logged in as a visitor and saved specific search requirements and then logged out. Then I logged in as Administrator and added a listing matching these requirements, but I have only received cron daemon in my admin email, as I have reported to you, but absolutely no notification in my visitor email.

Staff
9,968 Points
2014-07-01 6:00 pm
Hello Lascelles, no problem at all, glad to help.

I did see all of the info you had posted but did strip out the majority of it, since it was just showing the normal output for what curl or wget outputs, and because it contained your domain information.

The cron job you've setup isn't actually going to do anything on its own. It's up to the specific script and URL you're requesting to actually do any work on your site. The cron job is just a way of automating that task by sending a request to the URL at a time interval.

So if there is a particular URL that you go to that sends out the emails to your visitors, that's the URL you'd want to set your cron job to go to in order to automate that task.

So basically, I'd test first to make sure you can do what you need to in a web-browser, also making sure that you aren't logged in as the admin or anything. Then if you're hitting a particular URL to start sending out the notification emails and it works from your web browser (again not logged in as the admin) then you could use that URL in your cron job to do that task on a set schedule.

If you have to login as the admin in order to complete the task, then that's a whole different story because then you'd have to pass along your admin credentials in the curl or wget request so that it handles it the same way. For instance when I try the full URL that you had shown in your access-logs in my web-browser I get Invalid Token. So not sure if it requires you to be logged in.

It looks like you're probably running a Joomla site and the com_iproperty component is responsible for handling your email notifications. You might need to consult the documentation of this component to see what it recommends for setting up cron jobs specific to it.

- Jacob
n/a Points
2014-07-02 6:12 pm

Thanks again Jacob.

Yes I have a Joomla/com_ip site. The cronscripts appear to be setup correctly but I'm not getting the desired results from the fetched URL, so I am currently in touch with the relevant developers. I will post here again as soon as I have some developments.

Staff
9,968 Points
2014-07-02 6:15 pm
Hello Lascelles,

No problem at all, glad to help. Hopefully they'll have an answer for you, please check back and let us know what you find out. If they need any info from us at all just let us know!

- Jacob
n/a Points
2014-07-06 9:18 am

Hi Jacob,

I've followed your advice and I get this error:

/usr/local/cpanel/bin/jailshell: /usr/bin/wget: Permission denied

The command I'm using is:

wget --silent 'http://www.mysite.com/path/to/job'

When I run this job directly from my browser it works, but when I run it from cron tab I get the above error.

Can you advice what I'm doing wrong?

Thanks,

Birgir

Staff
9,968 Points
2014-07-06 4:24 pm
Hello Birgir,

If you are getting the /usr/bin/wget: Permission denied error, you'll want to use curl instead as wget has been disabled for users on your website.

Please let us know if you're still having any issues.

- Jacob
n/a Points
2014-07-07 1:54 pm

Hello Jacob,

I changed it to curl but now I get this error:

Error 406 - Not Acceptable

An error has occurred. Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.

Any idea?

Thanks,

Birgir

Staff
16,603 Points
2014-07-07 3:29 pm
Hello Birgir,

Sorry for the continuing problem. It appears that you're not including the user agent in your statement. Also, if you read Jacob's comments on this issue, he indicates that user credentials need to be included. This is why you are running into the mod_security issue. I hope this helps to provide some answers. Check out this article on using CURL if you require more details.

Kindest regards,
Arnel C.
n/a Points
2014-08-06 3:48 pm

I tried:

/usr/bin/curl --user-agent cPanel-Cron http://mywebsite.com/amazon/amazon_order/batch_by_system

 /usr/bin/curl --user-agent local http://mywebsite.com/amazon/amazon_order/batch_by_system

these two didn't work. any idea?

Staff
8,769 Points
2014-08-06 4:42 pm
Hello Young,

Thank you for your question. I confirmed your cron jobs ran successfully in the server logs.

For example, your curl cron is running, but nothing happens because it's just displaying the page after.

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

-John-Paul
n/a Points
2014-08-06 5:57 pm

Thank you for your quick response John!

Now, I know my curl command through cron job is working, but my system doesn't recognize the amazon batch report if the command is ran through cron job. 

But I checked my system reported two cron jobs that ran by you, but it doesn't recognize cron jobs set by me. How did you run those cron jobs? What would be the difference that your test run is recognized, but mine doesn't?

Staff
18,098 Points
2014-08-06 6:56 pm
Hello Young,

John-Paul did not run a separate test but confirmed that your cronjobs did indeed run on the server.

Kindest Regards,
Scott M
n/a Points
2014-08-23 2:50 am
i think i was alright

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

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

31 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

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

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!