*New 11.3 series Release:
2019-10-05: XigmaNAS 11.3.0.4.6928 - released, 11.2 series are soon unsupported!

*New 12.0 series Release:
2019-10-05: XigmaNAS 12.0.0.4.6928 - released!

*New 11.2 series Release:
2019-09-23: XigmaNAS 11.2.0.4.6881 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

[SOLVED] How to run php script from the inside cron?

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
User avatar
Snufkin
Advanced User
Advanced User
Posts: 289
Joined: 01 Jul 2012 11:27
Location: Etc/GMT-3 (BSD style)
Status: Offline

[SOLVED] How to run php script from the inside cron?

#1

Post by Snufkin » 28 Aug 2018 21:04

Recently I've set up new XNAS machine with Nextcloud installed via OBI.
And now it's a good time to run various destructive non-production tests.

There is recomendation in Nextcloud Administration Manual to use operating system cron feature for some background tasks.

I was able to start it successfully pushing manual button in XNAS cron web page.
It runs successfully with both root and www privileges in remote shell, but not from the inside cron.
Whatever I did with this php -f cron.php, it didn't work in cron! I've even failed to see simple php -v output...

The www cron job which is defined in XNAS web UI, performed without any doubt, check it in script writing current user environment to dedicated log.

Does anybody know magic spell to make this php script cooperate with cron?
Last edited by Snufkin on 07 Sep 2018 18:31, edited 1 time in total.
XNAS 11.3.0.4 embedded, ASUS P5B-E, Intel DC E6600, 4 GB DDR2, 2 x HGST HDN726040ALE614, 2 x WDC WD5000AAKS, Ippon Back Power Pro 400

User avatar
ms49434
Developer
Developer
Posts: 715
Joined: 03 Sep 2015 18:49
Location: Neuenkirchen-Vörden, Germany - GMT+1
Contact:
Status: Offline

Re: How to run php script from the inside cron?

#2

Post by ms49434 » 29 Aug 2018 09:08

Could you please try to enter the full path to php-cgi in your cron scripts, i.e. /usr/local/bin/php-cgi -f /path/to/cron.php
1) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 22GB out of 32GB ECC RAM, LSI 9300-8i IT mode in passthrough mode. Pool 1: 2x HGST 10TB, mirrored, SLOG: Samsung 850 Pro, L2ARC: Samsung 850 Pro, Pool 2: 1x Samsung 860 EVO 1TB , services: Samba AD, CIFS/SMB, ftp, ctld, rsync, syncthing, zfs snapshots.
2) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 8GB out of 32GB ECC RAM, IBM M1215 crossflashed, IT mode, passthrough mode, 2x HGST 10TB , services: rsync.

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4918
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: How to run php script from the inside cron?

#3

Post by raulfg3 » 29 Aug 2018 09:23

12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

User avatar
Snufkin
Advanced User
Advanced User
Posts: 289
Joined: 01 Jul 2012 11:27
Location: Etc/GMT-3 (BSD style)
Status: Offline

Re: How to run php script from the inside cron?

#4

Post by Snufkin » 29 Aug 2018 12:50

ms49434 wrote:
29 Aug 2018 09:08
Could you please try to enter the full path to php-cgi in your cron scripts, i.e. /usr/local/bin/php-cgi -f /path/to/cron.php
Above command line being run
  • manually hangs XNAS web GUI completely, and lighttpd restart doesn't resolve it.
    Second window/tab in browser for XNAS Web GUI gives following error

    Code: Select all

    Warning: session_start(): open(/tmp/sess_1bc09082379372548b9d191b36c66cfa, O_RDWR) failed: Permission denied (13) in /etc/inc/session.inc on line 52 Warning: session_start(): Failed to read session data: files (path: /tmp) in /etc/inc/session.inc on line 52 Warning: Cannot modify header information - headers already sent by (output started at /etc/inc/session.inc:52) in /usr/local/www/auth.inc on line 40 
  • by cron schedule filles Nextcloud own log with following errors

    Code: Select all

    {"reqId":"p9OVwaMK5Swwo1fGafpP","level":3,"time":"2018-08-29T10:15:00+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at \/mnt\/dsk\/services\/webserver\/nextcloud\/lib\/base.php#420","userAgent":"--","version":"13.0.5.2"}
    {"reqId":"p9OVwaMK5Swwo1fGafpP","level":3,"time":"2018-08-29T10:15:00+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at \/mnt\/dsk\/services\/webserver\/nextcloud\/lib\/base.php#424","userAgent":"--","version":"13.0.5.2"}
    {"reqId":"p9OVwaMK5Swwo1fGafpP","level":3,"time":"2018-08-29T10:15:00+00:00","remoteAddr":"","user":"--","app":"base","method":"--","url":"--","message":"Exception: {\"Exception\":\"ErrorException\",\"Message\":\"session_name(): Cannot change session name when headers already sent\",\"Code\":0,\"Trace\":\"#0 [internal function]: OC\\\\Session\\\\Internal->trapError(2, 'session_name():...', '\\\/mnt\\\/dsk\\\/servic...', 206, Array)\\n#1 [internal function]: session_name('oc3px3frldmp')\\n#2 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/Session\\\/Internal.php(206): call_user_func_array('session_name', Array)\\n#3 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/Session\\\/Internal.php(52): OC\\\\Session\\\\Internal->invoke('session_name', Array)\\n#4 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(436): OC\\\\Session\\\\Internal->__construct('oc3px3frldmp')\\n#5 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(664): OC::initSession()\\n#6 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(1081): OC::init()\\n#7 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/cron.php(41): require_once('\\\/mnt\\\/dsk\\\/servic...')\\n#8 {main}\",\"File\":\"\\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/Session\\\/Internal.php\",\"Line\":182}","userAgent":"--","version":"13.0.5.2"}
    {"reqId":"p9OVwaMK5Swwo1fGafpP","level":3,"time":"2018-08-29T10:15:00+00:00","remoteAddr":"","user":"--","app":"cron","method":"--","url":"--","message":"Exception: {\"Exception\":\"ErrorException\",\"Message\":\"Undefined index: SERVER_PROTOCOL\",\"Code\":0,\"Trace\":\"#0 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/AppFramework\\\/Http\\\/Request.php(676): OC\\\\Session\\\\Internal->trapError(8, 'Undefined index...', '\\\/mnt\\\/dsk\\\/servic...', 676, Array)\\n#1 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/legacy\\\/response.php(82): OC\\\\AppFramework\\\\Http\\\\Request->getHttpProtocol()\\n#2 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(447): OC_Response::setStatus(500)\\n#3 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(664): OC::initSession()\\n#4 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/base.php(1081): OC::init()\\n#5 \\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/cron.php(41): require_once('\\\/mnt\\\/dsk\\\/servic...')\\n#6 {main}\",\"File\":\"\\\/mnt\\\/dsk\\\/services\\\/webserver\\\/nextcloud\\\/lib\\\/private\\\/Session\\\/Internal.php\",\"Line\":182}","userAgent":"--","version":"13.0.5.2"}
    {"reqId":"p9OVwaMK5Swwo1fGafpP","level":3,"time":"2018-08-29T10:15:00+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"Undefined index: SCRIPT_FILENAME at \/mnt\/dsk\/services\/webserver\/nextcloud\/lib\/base.php#144","userAgent":"--","version":"13.0.5.2"}
    
    human readable picture
    nextcloud-cron-error.JPG
raulfg3 wrote:
29 Aug 2018 09:23
answer on FAQ0043: https://www.xigmanas.com/wiki/doku.php?id=faq:0043
I've seen this article that's why made nested call for php through script to see the environment (see my initial post).

Code: Select all

date >> nextcloud-cron.log
id >> nextcloud-cron.log
pwd >> nextcloud-cron.log
set >> nextcloud-cron.log
php -v >> nextcloud-cron.log
In the log I can see all the command output except php, and environment definitely points to www user.
You do not have the required permissions to view the files attached to this post.
XNAS 11.3.0.4 embedded, ASUS P5B-E, Intel DC E6600, 4 GB DDR2, 2 x HGST HDN726040ALE614, 2 x WDC WD5000AAKS, Ippon Back Power Pro 400

User avatar
Snufkin
Advanced User
Advanced User
Posts: 289
Joined: 01 Jul 2012 11:27
Location: Etc/GMT-3 (BSD style)
Status: Offline

Re: How to run php script from the inside cron?

#5

Post by Snufkin » 07 Sep 2018 18:30

Many thanks to combined efforts of XigmaNAS developer's team!

php and cron issue resolved in XigmaNAS release 11.2.0.4.5925

Nextcloud admin page <your server IP address>/nextcloud/index.php/settings/admin indicates successful completion of the cron job.
XNAS 11.3.0.4 embedded, ASUS P5B-E, Intel DC E6600, 4 GB DDR2, 2 x HGST HDN726040ALE614, 2 x WDC WD5000AAKS, Ippon Back Power Pro 400

Post Reply

Return to “Scripts and shell tips”