Sunlander

Well-Known Member
May 7, 2018
66
4
8
UK
cPanel Access Level
Root Administrator
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:
Code:
Set-Cookie: 8cac5803f4f9a1f069b632a35809cb55=92a85121cbcabb36091bbbb565a5fe81; path=/; domain=www.mysite.com; secure; HttpOnly
Content-type: text/html; charset=UTF-8
array(1) {
  [0]=>
  string(169) "<br>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<br>"
}
I don't know what else to try to get it to run automatically from cpanel
 
Last edited by a moderator:

Sunlander

Well-Known Member
May 7, 2018
66
4
8
UK
cPanel Access Level
Root Administrator
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) "<br>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<br>"

Does this mean anything to you with regards to why the cron wont run?
 

rpvw

Well-Known Member
Jul 18, 2013
1,100
475
113
UK
cPanel Access Level
Root Administrator
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:
  1. The script works 100% if you call it via a browser
  2. The script fails if called by cron even though the cron job is executing whatever php it can, and outputting raw HTML/JS code
  3. The script fails if called by command line in a shell terminal (full output unknown).
The following link might help: it is possible to use ajax, jquery page with cron? - the most relevant part being
When you run it from command line using cron like say /usr/bin/php mywebpage.php then the php executable DOES NOT parse/understand the other web technologies and so your page will fail.
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.
 

Sunlander

Well-Known Member
May 7, 2018
66
4
8
UK
cPanel Access Level
Root Administrator
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?
 

rpvw

Well-Known Member
Jul 18, 2013
1,100
475
113
UK
cPanel Access Level
Root Administrator
When you say try running it with CURL what exactly does that entail?
You could try something like
Code:
/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
Code:
/usr/bin/curl http://your.web/page.php
curl - Tutorial
 
Last edited:

Sunlander

Well-Known Member
May 7, 2018
66
4
8
UK
cPanel Access Level
Root Administrator
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 https://www.mysite.com/script.php
array(1) {
[0]=>
string(201) "<br>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:eek:pen3.xml<br>"
}

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 https://www.mysite.com/script.php

ran it in SSH and it returned this:

/usr/bin/wget -O /dev/null https://mysite.com/script.php
--2018-06-09 21:03:50-- https://mysite.com/script.php
Resolving mysite.com.au... 32.47.229.182
Connecting to mysite.com|32.47.229.182|:443... connected.
HTTP request sent, awaiting response... 200 OK
Cookie coming from mysite.com attempted to set domain to mysite.com
Length: unspecified [text/html]
Saving to: `/dev/null'
[ <=> ] 239 --.-K/s in 0s
2018-06-09 21:03:50 (28.0 MB/s) - `/dev/null' saved [239]
 

rpvw

Well-Known Member
Jul 18, 2013
1,100
475
113
UK
cPanel Access Level
Root Administrator
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 Stack Overflow - Where Developers Learn, Share, & Build Careers
 

Sunlander

Well-Known Member
May 7, 2018
66
4
8
UK
cPanel Access Level
Root Administrator
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
 

rpvw

Well-Known Member
Jul 18, 2013
1,100
475
113
UK
cPanel Access Level
Root Administrator
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