tags:

views:

50

answers:

2

I am running a cron job every five minutes which calls a php script to check to see if users have imported any files for processing.

When I run the php script by going to the address in my web browser it runs the script and then sends the user a notification by email. When I run the script using the cron job, the script works fine, but it doesn't send the user an email. Any thoughts about why no email is sent?

I'm running Ubuntu Hardy LTS. The cron job is:

*/5 * * * * /usr/bin/wget -–delete-after http://www.mywebsite.com/import_processing.php >/dev/null 2>&1

I'm using delete-after so that I don't get copies of the script piling up in my server directory. I'm suppressing output and errors also as I don't need email confirmation myself.

The script uses the basic mail function, and as I said, works just fine when run from my browser.

Update: It looks like the issue is my php script is looking for a browser cookie to send the email. I imagine I'll have to find another way to get the user's identity.

+1  A: 

run it like this

*/5 * * * * /usr/bin/php /var/www/htdocs/blah/blah/import_processing.php >/dev/null 2>&1

when you use wget you are downloading the file, with php you are running the file, test your script running

/usr/bin/php /var/www/htdocs/blah/blah/import_processing.php >/dev/null 2>&1

using the local path, just in case run

$ which php 

to figure out where it is installed

Juan Diego
Thanks for the suggestions. I got the same result. I think I have an idea of the problem. The script relies on reading a browser cookie to find the email address of the user, which I imagine won't work using wget or running php. So unless I'm wrong, I'll have to rewrite it to get around the browser cookie issue.
mandel
Juan Diego
A: 

The script was running properly using wget or php; the problem was that the php script looked for a browser cookie which didn't exist when the page was run outside of a web browser.

I changed the php script to do a database lookup instead and it worked just fine. Thanks for your suggestions.

mandel