InMotion Hosting Support Center

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 8: 301: How to run a cron job
Section 7: How to find which users are attached to databases
Section 9: How to force a dedicated SSL using the .htaccess file
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
11,186 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
34,213 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
11,186 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
11,186 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
11,186 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
11,186 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
34,213 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
24,525 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
39,022 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
n/a Points
2014-11-13 2:20 pm

Hi,

I've set up a crontab that runs a php script. It launches ok but quits unexpectedly after about 5 minutes of execution. The command is php -q /home/user/batch/script.php

Do you know what could be wrong? The script runs ok if i launch it from ssh, but not using your crontab feature..

Staff
24,525 Points
2014-11-13 2:51 pm
Hello Lauren,

Thank you for your question. I would first check for any PHP errors being generated. If you are hosted with us, you can view PHP errors in cPanel.

We are happy to help further, but would have to see the nature/code of the script to troubleshoot further.

Thank you,
John-Paul
n/a Points
2014-11-13 3:45 pm

Hi John-Paul and thanks for your support. Yes, I'm hosted by you guys. I checked for error_log files in the directory where the batch is triggered (or anywhere else for that matter) without success. Like I said, the script has been tested extensively using ssh to log remotely to the server hosting my files, but won't sustain more than 5 minutes of execution using crontab. the script is named grabphrasesbatch.php and located in /home/compag6/batch/

It is quering 3 restful apis and consuming some network resources. It also updates database tables created on the fly, and starts by loading a big list in memory. But the cron is emailing me when the job exits, again with no errors in the traces of the email.

If you need further input, or need anything else to assist

cheers 

Staff
24,525 Points
2014-11-13 5:54 pm
Hello laurent,

Thank you for your question. 5 minutes is a really long time for a PHP file to run, and it may be reaching a limitation for a Shared Hosting environment.

It may may be easier to submit a ticket to review your account at the time the cron jobs are running.

This also allows them to provide account specific information in a secure and private setting.

Thank you,
John-Paul
n/a Points
2014-11-14 3:32 am

yeah, i suspect something like this.

Ok, thanks again for your support

n/a Points
2015-05-23 1:17 pm

I'm confused, I'm afraid... So... shared server..

I see how a curl cron job can be constructed, however in the article...

http://www.inmotionhosting.com/support/website/wordpress/disabling-the-wp-cronphp-in-wordpress

It says to make the cron job like this...

cd /home/userna5/public_html; php -q wp-cron.phpI'm asking because I've been using the above and it's been fine but it's now causing a problem with the new version of the Wordfence plugin.In the Wordfence plugin support, they are recommending using a wget... but that's not available on inMotion shared hosting and you say to use curl.Can you unconfuse me and definitively say what I should use as a cron statement if I want to disable the wp-cron and instead run the cron from my cPanel?Thanks! 
Staff
10,077 Points
2015-05-27 12:13 am
Hello Ken,

You can use curl by following the guide in the following article.

Best Regards,
TJ Edens
n/a Points
2015-05-27 11:45 am

Hi TJ,

Thank you for the link about making a cron job. I have seen that article... In fact it's the same article that this thread is in!

My question is that this article says to use...

/usr/bin/curl --user-agent cPanel-Cron http://example.com/cron.php (for WordPress I assume it should be wp-cron.php)and the "Disable wp-cron in WordPress" article says to use...cd /home/userna5/public_html; php -q wp-cron.phpWhich is preferred? In what ways are they different? Obviously one is a curl... what's the other?Seeing two different ways of "properly" doing a cron job is confusing. I'd appreciate a detailed response please.
Staff
34,213 Points
2015-05-29 10:32 am
Hello Ken,

Sorry for the problems with writing a cron job with CURL. Mainly, this option is provided for advanced user - and little to no documentation. We unfortunately can't provide to much information on it, as it should be typically setup by a programmer with knowledge. Additionally, this delves into the realm of providing code, which is normally not something within our scope of our support. However, you might want to check out these two posts as they may provide the information that you seek:

Creating a Cron Job
Examples of CURL

I hope this helps to answer your question, please let us know if you require any further assistance.

Regards,
Arnel C.
n/a Points
2015-09-07 2:02 am

How does the cron.php file trigger the sitemap.xml regenration automatically? And how does it trigger the regenration of  the googleproducts.xml file?  Are there specific command lines necessary within the cron.php file that address these in order to trigger the function?

Staff
24,525 Points
2015-09-08 5:53 pm
Hello Oscar,

Thankyou for contacting us. The above guide explains how to schedule and setup a cron. It will then trigger the script at the intervals you specify.

You will have to code the script to function as needed.

Thank you,
John-Paul
n/a Points
2015-10-08 6:21 pm

Hello,  Can you please show me how to write this so it will work on an Inmotion server?  Thank you.

 

wget -O /dev/null "http://plantmanagement.com/wpblog/?wpmlmethod=docron&auth=115f89503138" > /dev/null 2>&1

Staff
24,525 Points
2015-10-09 10:05 am
Hello Steve,

Thank you for contacting us. As explained above "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."

This is covered in the section above titled Using the User Agent String.

Thank you,
John-Paul
n/a Points
2015-12-26 4:22 am

You can try out various Crontab timing values offline at www.cronsandbox.com - it gives you a list of job run date/times for whatever minute, hour, etc you enter.

n/a Points
2016-01-12 3:43 pm

Hello, i set up cron job using cd /home/userna5/public_html; php -q wp-cron.php

and i was getting this warning message each time the cron job runs <br /> <b>Warning</b>:  session_start(): Cannot send session cookie - headers already sent in <b>/home/userna5/public_html/

wp-content/plugins/wordpress-social-login/wp-social-login.php</b> on line <b>64</b><br /> <br /> <b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent in <b>/home/userna5/public_html/wp-content/plugins/wordpress-social-login/wp-social-login.php</b> on line <b>64</b><br />

 

then i was adviced to use the cURL cron and after setting it up i got this message 

% 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   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

Can you tell me if the cron is working successfully

Staff
4,853 Points
2016-01-12 3:51 pm
Hello Kingsley,

We'll be happy to look for you and see if it's running. I recommend you contact our Live Support so we can get the proper account verification.
n/a Points
2016-01-19 2:18 pm

Hello,

 

I could not stop to receive emails

 

this is the job (that's working)

 

php -q /home/cnstrdm3/public_html/logcon/GravaClientes.php /dev/null 2>&1

 

Thanks

Staff
4,853 Points
2016-01-19 7:11 pm
Would be be able to clarify your request about email? Or, do you want to see if your job is running?
n/a Points
2016-01-20 10:34 am

Sure. The cron job is working but we do not want to receive emails.

we tried to put /dev/null 2>&1at the end of cron job but we still receive emails.

 

Thanks

Staff
34,213 Points
2016-01-20 11:30 am
Hello Paulo,

If you want to stop the emails - per the documentation for cPanel, you simply need to click on Cron Jobs in cPanel, then make sure the email field is BLANK andl then click on the UPDATE button. It will ask you if you wish to NOT receive emails. Confirm this and then you should be good to go.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2016-01-21 9:59 am

Thanks Arn

We will have 3 to 4 cron jobs.

Is it posible to stop the email for only one cron job?

Thanks

 

Staff
24,525 Points
2016-01-21 3:57 pm
Hello Paulo,

Thank you for contacting us. I spent some time looking into this, and could not find a built in way in cPanel. This may possibly be accomplished with custom coded/developed script.

Thank you,
John-Paul
n/a Points
2016-01-23 1:38 pm

Hello John-Paul

 

Thanks for your attention

 

Paulo

n/a Points
2016-03-09 11:32 am

/home/teckcom/public_html/pari/index.php

will it work or not?

Staff
34,213 Points
2016-03-09 9:51 pm
Hello Mr-AxE,

We're not sure what you mean by the file location and your question. Please provide more information about what you're trying to do and we can look into it further.

If you have any further questions, please let us know.

Kindest regards,
Arnel C.
2016-08-05 10:02 pm
I am trying to create a script that will automatically search a folder and all subfolders for .mp3 and .wav files that are older than 45 day and then automatically delete them.

Would the following script work?

#!/usr/local/bin/php


2016-08-05 10:03 pm
UGH!!! This is the script..

#!/usr/local/bin/php
2016-08-05 10:05 pm
I am unable to post my script. Arggh!!! Going to use odd spacing.

# ! / usr / local / bin / php
< ? php

rm -rf ~/public_html/audio/*{.wav,.mp3}

// ...

?>
Staff
39,022 Points
2016-08-08 2:16 pm
No, the code you provided will not work as it is written. Did you test the command line code to make sure it works first? You want to test your command line script to get it to work properly. Then you can add it to your php file. You will need to use the 'exec()' command with your script as the command line script will not simply run just because it is enclosed in php tags. It should look like below:
<?php
exec('rm -rf /public_html/audio/*{.wav,.mp3}')
?>
2016-08-08 3:33 pm
Thank you. It is a starting point. I am not a coder and am simply looking for a way to autodelete files via a daily cron job so my server does not get filled up with old material.

Would I save the script you have written as a php file in the /bin file and then write the file name in the command line?
Staff
39,022 Points
2016-08-08 4:03 pm
You can save the php file wherever you like in your account as long as the path in the cron command line points to it.
2016-08-09 1:36 pm
Scott, you have been so helpful. Thank you.

Do I have the code right to only delete files older than 45 days old?



THANK YOU!
Staff
4,853 Points
2016-08-09 1:55 pm
It looks like the code you have posted above will only delete the files currently in that folder regardless of age.

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.

64 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!