Click to See Complete Forum and Search --> : [SOLVED] CRON not PHP'ing


pugg09
12-12-2005, 10:20 PM
Has anyone seen this?

I've created a PHP script to query my MySQL database and send emails to some of my clients. When I perform the script manually from the console (ie. php /var/www/html/myscript.php) it works everytime. However, when I try to get cron to do it, nothing gets sent yet my cron log shows that the script was run.

Any suggestions?

Icarus
12-12-2005, 10:59 PM
Make sure you enter the full paths the the commands ypu want to run and that the script is executable.

Otherwise, try sending the output to a file so you can better see why it's not working. (hint: add a '&> file.txt' at the end ;))

dkeav
12-12-2005, 11:43 PM
are you using cron.daily etc etc or crontab?

pugg09
12-13-2005, 10:23 AM
Thanks for the replies.... I'll will try outputting to text now, however, when you mean "full path" you are talking about the full path (from root) to where my script it right?

I'm using crontab, not cron daily.

pugg09
12-13-2005, 10:35 AM
Hi Icarus - this seems a bit ambiguous, but all that is in the text file is blank line.

serz
12-13-2005, 11:53 AM
Hi are you running the script? You didn't answer that question.. por your /etc/crontab or something.

dkeav
12-13-2005, 02:22 PM
full path means dont just put rm in your crontab, it needs to be /usr/bin/rm for example

pugg09
12-13-2005, 08:39 PM
ok. here's exactly what's in crontab when i 'pico' it.

0-59/5 * * * * php /var/www/html/mail.php &> /var/www/html/cronstuff/phpmail.txt

serz
12-13-2005, 08:45 PM
0-59/5 * * * * php /var/www/html/mail.php &> /var/www/html/cronstuff/phpmail.txt

What do you want to do there? Run the script every minute? If so.. that should be */1 instead of 0-59/5..

pugg09
12-13-2005, 10:01 PM
Nope, just every 5 minutes....it checks my MySql db for messages and is 'supposed' to send email to whoever has some.

dkeav
12-13-2005, 10:18 PM
it should be */5

pugg09
12-13-2005, 10:35 PM
Ok, I switch to */5 and now my log file (phpmail.txt) says this:

X-Powered-By: PHP/4.1.2
Content-type: text/html

Still no email being sent.

dkeav
12-13-2005, 11:08 PM
perhaps you dont have permission, you should try running as a specified user

0-59/5 * * * root php /var/www/html/mail.php &> /var/www/html/cronstuff/phpmail.txt

pugg09
12-14-2005, 11:29 AM
ok, i normally run it as root since i am root and it is my own box. i'll try running it as a user.

pugg09
12-15-2005, 06:53 PM
hi folks.... i've done some more digging and found that the script is actually choking on my mysql connection statement - i'm still stuck, here are the lines of code i'm using to connect to my database server

$myHostname = "192.168.0.101";
$myUser = "root";
$myPass = "mypassword";
$myDB = "messages_db";

$db = @mysql_pconnect($myHostname,$myUser,$myPass);

it seems to be choking on the line that starts with '$db' any suggestion as to why?

serz
12-15-2005, 08:23 PM
$db = @mysql_pconnect($myHostname,$myUser,$myPass);Is that a typo?

pugg09
12-15-2005, 08:39 PM
sorry, yes that is a typo - it should be without the 'p'

serz
12-15-2005, 10:42 PM
Hm.. remove the @ so you can see errors, this way you can see what's going on.

pugg09
12-15-2005, 10:47 PM
ok, i removed it and ran it manually as root (ex php myscript.php) there was no problem. it's just when i put that same command in my crontab - it dies everytime.

pugg09
12-15-2005, 11:07 PM
ok, i've got the server response going to a log file. the latest reply says this:

<b>Fatal error</b>: Call to undefined function: mysql_connect() in <b>/var/www/html/moremail.php</b> on line <b>13</b><br>

Ok, then i did a phpinfo on my machine and the Configure Command does say "--with-mysql' "

Am I out of luck with this problem?

pugg09
12-18-2005, 09:53 PM
Hm.. remove the @ so you can see errors, this way you can see what's going on.

I FINALLY FIXED IT!!! I was think about using Lynx to activate my PHP script since cron was giving me errors (see thread). But when I sent the result to my log file I was getting "Command not found - Lynx". When investigating that fix, it was noted that if you included the full path (/usr/local/bin/lynx) of the command in the Crontab, then Lynx commands work. So I did the same for my PHP command and it worked!

In short this is what I had that didn't work:

46 * * * * root php /var/www/html/mailman.php

and this is what DID work:

46 * * * * root /usr/local/bin/php /var/www/html/mailman.php

Thanks everyone for your input.

serz
12-19-2005, 02:00 AM
Great.. glad you could fix it :)