0

in my crontab there is a script starting at 2:40 AM, executing some routines both from sh commands and php scripts starting from sh files.

the line in crontab looks like this:

SHELL=/BIN/BASH
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mypath

40 2 * * * root run-parts /etc/cron.twoam

inside the folder cron.twoam there is one script, let's call it script1: inside script 1 some other scripts get called, and they are executed fine. Then it comes time of this script let's call it script2, called from script1. i leave traces both on txt files and system logs to check what happens.

echo "exec script2" >> /mypath/txtlog
/mypath/script2 > /mypath/txtlog2
echo "end of script2" >> /mypath/txtlog
logger -p local1.info "09@ script2 executed"
echo "end of crontwoam" >> /mypath/txtlog
date >> /mypath/txtlog

.... other script that runs fine

now let's see what is inside script2:

some scripts....
/mypath/subpath/script3
other scripts...

now let's check script3:

various php commands
cd /phppath/
php /phppath/myscript.php >> /mypath/myphplog
php /phppath/otherscript.php >> /mypath/myphplog

other commands

and finally comes the php script. the php script has various included script. every one of them execute normally except one. whenever i put it from line 2 to line 90 the execution will silently stop there.

so it comes the part where i do

include("phpscript2.php");

and things after does not get executed.

phpscripts2.php runs fine if executed by command line with php phpscripts2.php by my user or by root.

inside phpscripts2 there is ( i include meaningfull parts):

echo "started phpscripts2" exec("mysqldump ......"); ftp_connect(); file_get_contents("https://someotherscriptsondifferentserver"); echo "ended phpscripts2"

now what i find in logs: in /mypath/txtlog i found both

exec script2

and

end of script 2

in myphplog i found

started phpscript2

and row after

started otherphpscript

i' m missing end of phpscript2 that end prematurly. run time of phpscript2 is about 2 minutes.

i can't find traces in any log of some error. where could i look?

EDIT:

i forgot to add that if make a sh file that calls just this script, and i make a custom crontab line to call it just for test, everything runs.

  • You should instrument your phpscript2 some more and attempt to find out how far it gets. You should also probably capture the file output of the script etc. – user9517 supports GoFundMonica Dec 5 '15 at 9:09
  • what is fill output? if the script output anything like a warning it gets logged in txtfile. – AndreaBogazzi Dec 5 '15 at 9:12
  • You're not capturing stderr in the script so that should be sent by email to the cron file's owner. To capture stderr use 2>&1 to send to the same file as stdout or 2> /some/other/file – Paul Haldane Dec 5 '15 at 22:53
  • php is like csh in one way: very finicky about its environment, control tty, and so on. i never got either kind of script to run inside cron, so i do what you're describing-- call the csh or php script from a sh script, and exec that sh script from your crontab. in other words this is a known bug in cron, and always has been, and your workaround (gateway through a sh script) is what everybody does. – Paul Vixie Jan 13 '16 at 21:18
0

You're not capturing stderr in the script so that should be sent by email to the cron file's owner. To capture stderr use 2>&1 to send to the same file as stdout or 2> /some/other/file

This was the comment that lead me to the problem.

i redirected the stdErr in a text file and i could finally see it. I had a duplicate function that was coming out just in crontab. This because the full script had a series of require_once plus a lonely require. This was of no harm untill i added a small function in a common required file and i did not notice that there was still a require in place of require_once. The error was mailed of course from crontab but i did not setup the sendmail yet so nothing was coming out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.