Setting up cronjob questions
Hi,
I have a problem getting my cron jobs to run. I have searched this forum for the answer and also googled it and tried all the suggestions there.
Basically I have a couple of php files that need to be run via cron. These files run correctly if I enter the following in the url:
php -f /home/mysite/public_html/myscript.php
None of them seem to work. Could it be that I need to enable something somewhere on WHM Easyapache to get them to work?
Any advice would be greatly appreciated
Kind regards
-
Hi, thanks for answering. Unfortunately that doesn't work either. May I ask, what does the file permission need to be with a cron job? I have tried 644, 744 but still no effect. I have read the cpanel help on cron jobs and there is only one example (which didn't work for me). I wondered if the actual cron job needs to be enabled somewhere in the server settings? 0 -
Hi Michael, apologies for delay responding. I have just tried your suggestion and it doesn't like that either. I don't understand what might be preventing it from running. Like I said in my original post it runs perfectly if I do it from the url, which is why I wondered if it may be a server setting? 0 -
Couple of things that you could try: The domain specific call detailed in the following post might work if you are using ea4 cPanel MultiPHP Manager Hello, You should use one of the following commands for PHP with your cron jobs: General example:
/usr/local/bin/php /home/$user/public_html/path/to/cron/script
Domain-specific example:/usr/local/bin/ea-php56 /home/$user/domain_path/path/to/cron/script
In the above example, replace "ea-php56" with the PHP version assigned to the domain you wish to use. Look in the MultiPHP Manager for the actual PHP version assigned to a domain. Thank you.
If you are using Cloiulinux alt-php with PHP Selector, you could try constructing the call with something like/opt/alt/php72/usr/bin/php -q /home/mysite/public_html/myscript.php
(Change the php version to the one you are using on the domain) Hope something works for you :)0 -
Hi, I have ea4 and just tried your suggestions as follows: /usr/local/bin/ea-php72 /home/$user/public_html/script.php May I ask, should it say $user as I put above (I copied from your example) or should it be my proper root username? I did try the other but it still didn't run. 0 -
The php version should be changed to whatever the domain is set to use, and the /$user/ changed to the actual username that is in the path to the script. If nothing works, it might be worth checking if the php you are using has the cli module installed (you should ask your web host if you don't have root access) it is conceivable that the web host has chosen not to install it. 0 -
Hi, still cannot get it to work. I have root access (I am on php 72) and checked via easyapache that cli is installed for this and it is. I noticed there were other cli related modules that were unchecked - are all of those with cli in the title meant to be enabled do you know? I don't know if there is any test to check that cpanel is firing the cron jobs automatically? Or whether I can add the cron job to run using ssh - if that has more chance of working. At a bit of a loss with this now regarding what else to try 0 -
I don't know if there is any test to check that cpanel is firing the cron jobs automatically?
Hello, Yes, you can review the following log file to confirm the cron job is executing: /var/log/cron Can you let us know the entry the full entry that appears for the account? Also, if it's not running, make sure the crond service is not stopped:/scripts/restartsrv_crond
Thank you.0 -
Hi, the sites I am trying to run the crons on are mysite1 and mysite3 - this is the output from the code you gave me. it is script.php I am trying to run Jun 3 03:09:04 541267 run-parts(/etc/cron.daily)[5783]: finished logrotate Jun 3 03:09:04 541267 run-parts(/etc/cron.daily)[5717]: starting makewhatis.cron Jun 3 03:09:08 541267 run-parts(/etc/cron.daily)[5996]: finished makewhatis.cron Jun 3 03:09:08 541267 run-parts(/etc/cron.daily)[5717]: starting mlocate.cron Jun 3 03:10:01 541267 CROND[6088]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/script.php) Jun 3 03:10:01 541267 CROND[6081]: (mysite2) CMD (/usr/bin/wget -O /dev/null "https://www.mysite3.com/index.php?option=com_community&task=cr$ Jun 3 03:10:01 541267 CROND[6090]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:10:01 541267 CROND[6082]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/components/com_osproperty/cron.php) Jun 3 03:10:01 541267 CROND[6085]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/importIMG.php) Jun 3 03:10:01 541267 CROND[6084]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/cronxml.php) Jun 3 03:10:01 541267 CROND[6086]: (root) CMD (/usr/local/cpanel/scripts/dcpumon-wrapper >/dev/null 2>&1) Jun 3 03:10:01 541267 CROND[6089]: (root) CMD (/usr/bin/test -e /etc/cpanel-dovecot-solrdisable || /usr/local/cpanel/3rdparty/scripts/cpanel_d$ Jun 3 03:10:01 541267 CROND[6091]: (mysite3) CMD (/usr/local/bin/php /home/mysite3/public_html/script.php) Jun 3 03:10:01 541267 CROND[6092]: (root) CMD (/usr/lib64/sa/sa1 1 1) Jun 3 03:10:01 541267 CROND[6083]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/components/com_osproperty/cron.php) Jun 3 03:10:01 541267 CROND[6087]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:11:01 541267 CROND[6233]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:11:01 541267 CROND[6232]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:12:01 541267 CROND[6273]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:12:01 541267 CROND[6272]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:13:01 541267 CROND[6308]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:13:01 541267 CROND[6307]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:14:01 541267 CROND[6343]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:14:01 541267 CROND[6344]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:15:01 541267 CROND[6430]: (mysite3) CMD (/usr/local/bin/php /home/mysite3/public_html/script.php) Jun 3 03:15:01 541267 CROND[6431]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/components/com_osproperty/cron.php) Jun 3 03:15:01 541267 CROND[6432]: (mysite4) CMD (/usr/bin/php -f /home/mysite4/public_html/brookestone/cron/vtigercron.php) Jun 3 03:15:01 541267 CROND[6436]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:15:01 541267 CROND[6435]: (mysite2) CMD (/usr/bin/wget -O /dev/null "https://mysite3.com/index.php?option=com_easyblog&task=cronfee$ Jun 3 03:15:01 541267 CROND[6441]: (mysite3) CMD (/usr/bin/wget -O /dev/null "https://www.mysite3.com.au/index.php?option=com_community&$ Jun 3 03:15:01 541267 CROND[6443]: (mysite4) CMD (/usr/bin/php -f /home/mysite4/public_html/crm/cron/vtigercron.php) Jun 3 03:15:01 541267 CROND[6439]: (mysite4) CMD (/usr/bin/php -f /home/mysite4/public_html/brookestone/public_html/cron.php) Jun 3 03:15:01 541267 CROND[6434]: (mysite3) CMD (/usr/bin/wget -O /dev/null "https://mysite3.com.au/index.php?option=com_easyblog&task=$ Jun 3 03:15:01 541267 CROND[6446]: (mysite3) CMD (/usr/bin/php -f /home/mysite3/public_html/crm2/cron/vtigercron.php) Jun 3 03:15:01 541267 CROND[6437]: (mysite2) CMD (/usr/bin/wget -O /dev/null "https://www.mysite3.com/index.php?option=com_community&task=cr$ Jun 3 03:15:01 541267 CROND[6440]: (mysite2) CMD (/usr/bin/php -f /home/mysite2/public_html/components/com_osproperty/cronxml.php) Jun 3 03:15:01 541267 CROND[6447]: (mysite5e) CMD (/usr/bin/php -f /home/mysite5e/public_html/crm/cron/vtigercron.php) Jun 3 03:15:01 541267 CROND[6445]: (mysite3) CMD (/usr/bin/php -f /home/mysite3/public_html/components/com_osproperty/cronxml.php) Jun 3 03:15:01 541267 CROND[6433]: (mysite3) CMD (https://www.mysite3.com.au/index.php?option=com_komento&task=clearCaptcha) Jun 3 03:15:01 541267 CROND[6449]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/cronxml.php) Jun 3 03:15:01 541267 CROND[6442]: (mysite2) CMD (/usr/bin/php /home/mysite2/public_html/templates/jreviews_overrides/sendalert.php) Jun 3 03:15:01 541267 CROND[6450]: (mysite4) CMD (/usr/bin/php -f /home/mysite4/public_html/new/public_html/cron.php) Jun 3 03:15:01 541267 CROND[6451]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/importIMG.php) Jun 3 03:15:01 541267 CROND[6453]: (cscloudsolutions) CMD (/usr/bin/php -f /home/cscloudsolutions/public_html/crm/cron/vtigercron.php) Jun 3 03:15:01 541267 CROND[6438]: (mysite3) CMD (/usr/bin/php -f /home/mysite3/public_html/components/com_osproperty/importIMG.php)
0 -
Hello @Sunlander, The output shows the cron jobs are executing. You mentioned testing the PHP files via a web browser. Can you also try running the cron job command while logged in via SSH as the account username? This should help to narrow down the cause of the issue. Thank you. 0 -
Hi, I didn't realise there were pages of those. Below are the last ones. May I ask, do I run the cron as it is in the cron job i.e. like this: nano usr/bin/php /home/mysite1/public_html/script.php ? Jun 7 15:05:01 541267 CROND[3329]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/cronxml.php) Jun 7 15:05:01 541267 CROND[3330]: (mysite1) CMD (/usr/bin/php /home/mysite1/public_html/script.php) Jun 7 15:05:01 541267 CROND[3328]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/importIMG.php) :05:01 541267 CROND[3332]: (ltscom) CMD (/usr/bin/wget -O /dev/null "https://www.mysite3.com/index.php?option=com_community&task=cr$ Jun 7 15:05:01 541267 CROND[3336]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/components/com_osproperty/cron.php) Jun 7 15:05:01 541267 CROND[3338]: (mysite3) CMD (/usr/bin/php -f /home/mysite3/public_html/script.php) Jun 7 15:05:01 541267 CROND[3343]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:05:01 541267 CROND[3344]: (root) CMD (/usr/local/cpanel/scripts/eximstats_spam_check 2>&1) Jun 7 15:05:01 541267 CROND[3340]: (root) CMD (/usr/local/cpanel/whostmgr/bin/dnsqueue > /dev/null 2>&1) Jun 7 15:05:01 541267 CROND[3342]: (root) CMD (/usr/local/cpanel/scripts/dcpumon-wrapper >/dev/null 2>&1) Jun 7 15:07:01 541267 CROND[3494]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:08:01 541267 CROND[3615]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:09:01 541267 CROND[3656]: (root) CMD (/usr/local/cpanel/scripts/clean_user_php_sessions > /dev/null 2>&1) Jun 7 15:09:01 541267 CROND[3659]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:10:01 541267 CROND[3773]: (mysite1) CMD (/usr/bin/php /home/mysite1/public_html/script.php) Jun 7 15:10:01 541267 CROND[3771]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/cronxml.php) Jun 7 15:10:01 541267 CROND[3770]: (ltscom) CMD (/usr/bin/wget -O /dev/null "https://www.mysite3.com/index.php?option=com_community&task=cr$ Jun 7 15:10:01 541267 CROND[3772]: (mysite1) CMD (/usr/bin/php -f /home/mysite1/public_html/components/com_osproperty/importIMG.php) Jun 7 15:10:01 541267 CROND[3774]: (root) CMD (/usr/bin/test -e /etc/cpanel-dovecot-solrdisable || /usr/local/cpanel/3rdparty/scripts/cpanel_d$ Jun 7 15:10:01 541267 CROND[3776]: (ltscom) CMD (/usr/bin/php /home/ltscom/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:10:01 541267 CROND[3775]: (root) CMD (/usr/local/cpanel/scripts/dcpumon-wrapper >/dev/null 2>&1) Jun 7 15:10:01 541267 CROND[3780]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/components/com_osproperty/cron.php) Jun 7 15:10:01 541267 CROND[3782]: (mysite3) CMD (/usr/bin/php -f /home/mysite3/public_html/script.php) Jun 7 15:10:01 541267 CROND[3783]: (mysite3) CMD (/usr/bin/php /home/mysite3/public_html/templates/jreviews_overrides/sendalert.php) Jun 7 15:10:01 541267 CROND[3781]: (root) CMD (/usr/lib64/sa/sa1 1 1)
0 -
I actually just tried the code i asked about and this is the output [removed] 0 -
I would guess the problem is ^@^@^@^@^@^@^@^@EasyApache PHP config file not found: %s ^@^@^@^@^@^@^@Default PHP not defined in EasyApache configuration file ^@^@^@^@^@^@^@Configured PHP version %s does not have a CGI binary installed, using default PHP version ^@^@^@^@^@^@Default PHP version %s does not have a CGI binary installed, exiting ^@^@^@ea-php-cli Copyright 2017 cPanel, Inc. ^@php_cli unable to execute php :%d: (%d) :%s
Either your EA4 build is missing the relevant cli modules, or the EA config itself needs repairing.0 -
Hi, when I log in to SSH I see a message saying: ************************************************************* ************************ WARNING **************************** ************************************************************* Your server is currently being configured for cPanel. The cPanel installation changes a number of system files, and for this reason it is NOT RECOMMENDED that you use your server during this time. We'll send you an email when cPanel is installed and your server is ready to go! Best Wishes, The cPanel installer Could that be part of the problem? How do I repair EA4? Also when I am in the server I see this message: You must reboot the server to apply kernel updates. I am afraid to click this in case it deletes or damages my files. In EasyApache when I search for CLI these are the settings in attached image upload. Are there other things I need to install for this to work? Do I need to install CGI? 0 -
It rather looks like you have bigger problems that are way above my pay grade ........... over to Michael :-D 0 -
Below are the last ones. May I ask, do I run the cron as it is in the cron job i.e. like this: nano usr/bin/php /home/mysite1/public_html/script.php ?
Hello @Sunlander, You used the wrong command. "Nano" is a text editor. You'd run the same command that you enter when adding the cron job. EX:/usr/bin/php /home/mysite1/public_html/script.php
Thank you.0 -
Ah ... I just ran it without nano this is what it shows: # /usr/bin/php /home/mysite1/public_html/script.php Content-type: text/html; charset=UTF-8
0 -
Hello @Sunlander, It looks like the PHP script was successfully executed. Can you confirm that it performed the specific action you needed it to (whatever the script is supposed to do as part of the cron job)? Thank you. 0 -
Hi, the developer has now removed jquery frommthe script to address other issues so now when I try run the cron via SSH this is what is returned: Set-Cookie: 8cac5803f4f9a1f069b632a35809cb55=92a85121cbcabb36091bbbb565a5fe81; path=/; domain=www.mysite.com; secure; HttpOnly Content-type: text/html; charset=UTF-8 array(1) { [0]=> string(169) "
Error type:8 Error Message:Undefined index: SCRIPT_NAME Error Script FileName:/home/mysite/public_html/libraries/src/Uri/Uri.php Error XML FileName:eek:pen3.xml
" }
I don't know what else to try to get it to run automatically from cpanel0 -
Hi Michael, I did reply to this but I must not have clicked on post reply button - hense sorry for delay responding. The script developer has change the script now to address another issue, and now when I run that cron via SSH it shows this error message: Set-Cookie: 8cac5803f4f9a1f069b632a35809cb55=7f1091dfe4854a0720d569aa47aba874; path=/; domain=www.mysite.com; secure; HttpOnly Content-type: text/html; charset=UTF-8 array(1) { [0]=> string(169) "
Error type:8 Error Message:Undefined index: SCRIPT_NAME Error Script FileName:/home/mysite/public_html/libraries/src/Uri/Uri.php Error XML FileName:open3.xml
" Does this mean anything to you with regards to why the cron wont run?0 -
I believe you will need to re-write the code to get rid of all html/css/js/jquery/ajax and just run pure php, or re-write the code in some other format (codebase eg shell script) that does not require a browser to parse the included scripting components. If I am correct in what I am reading from your answers: - The script works 100% if you call it via a browser
- The script fails if called by cron even though the cron job is executing whatever php it can, and outputting raw HTML/JS code
- The script fails if called by command line in a shell terminal (full output unknown).
You could experiment with calling the cron file using curl - this often has mixed results when it comes to parsing anything other than pure php or html. If you search for "can cron run js" you will get a variety of answers, most telling you that you can't, and a few that have suggestions like using node.js that you may, or may not, be able to make work on your server, and others suggesting you call your script by curl as I previously suggested. In the long run, it would be quicker and easier to re-write the script you are trying to run in something that cron can execute. You may have to go back to your developer for help, as I don't believe your issue has anything fundamentally to do with cPanel.0 -
Hi, thanks for taking the time to reply. When I run script in browser it works perfectly. It doesn't run at all from the cpanel cron job. When I try to run it in SSH it just returns to the root with no message. It doesn't carry out the import on the website when run from SSH. I have put the question to the developer regarding what you say above. I think I am wearing them down with this :O( When you say try running it with CURL what exactly does that entail? 0 -
When you say try running it with CURL what exactly does that entail?
You could try something like/usr/bin/curl /full/path/to/your/script.php
although there is no guarantee that even this will execute code that requires a browser to parse. >>EDIT<< Sorry its been a long time since I used curl..... OR/usr/bin/curl http://your.web/page.php
curl - Tutorial0 -
Hi, I just tried that, I think I am getting close. When I run that in SSH it returns the following message: /usr/bin/curl Error type:2 Error Message:copy(media/reaxml/read/open3.xml): failed to open stream: Permission denied Error Script FileName:/home/mysite/public_html/script.php Error XML FileName:open3.xml
" } Then I spotted another cron in my cpanel - these seem to work for the scripts they run. It just produces an error for this particular file. I adapted one of the existing crons to this: /usr/bin/wget -O /dev/null --2018-06-09 21:03:50--0 -
I hate using curl, and hate wget even more.... wget has a habit of creating new files every time it is run (and they build up quickly) - check carefully that sending the output to /dev/null is preventing these files from being written (hint - check /tmp folders) If you must use curl or wget, make absolutely sure that you have sanitised any variables in your php or js so that that cannot be altered by any method (eg injection or PUT, POST, DELETE etc) and don't forget to do the same for any include files or files that are called as part of the cron job. Also, respect the danger of sql injection, and ensure that any sql based or destined data is both sanitised and adequately restricted. If possible, put the cron files into a folder that is inaccessible from everywhere but localhost to prevent them being arbitrarily run in a browser. Non of this is really within the scope of the WHM/cPanel forums - you will get better help from other resources like 0 -
Hi thanks. I have been all over stack overflow and tried all the solutions. The one last thing I want to try is folder ownership as some have suggested in their replies that this is sometimes the issue when crons don't run. However, I am not sure how I check this in SSH and also change it. Would you know what the settings should be? Does ownership need to be change for the actual script files too? There seems to be many people with issues around cron jobs 0 -
I think you are looking for a magic bullet ! The cron runs - so the permissions of the file being called by cron, or the folder that it is in; is not the issue. The issue is if the file does not do what it is intended to do - and that is down to the coding of the file, not the permissions - recode the file using only php that does not rely on any browser side processing, and that can be executed by the php-cli - and you will achieve what you want. Cron files should run perfectly well from folders (inside or outside of /public_html) that are set to 755, and the files themselves set to 644 0
Please sign in to leave a comment.
Comments
28 comments