PDA

View Full Version : Getting php script to run as cron



esiason14
04-22-2007, 12:14 AM
I've tried every possible way that I could think of and I still can't get this cron job to work. I've tried:

15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php
15 12 * * * wget http://www.mydomain.com/admin/getinjuries.php
15 12 * * * lynx http://www.mydomain.com/admin/getinjuries.php

etc, etc

The script parses a log and then dumps it into my db.

File is chmod to 755.

Preferably I would like to run it outside the www. Any pointers?

rolling
04-22-2007, 03:59 AM
15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php

Should work. Try it from the command line. If it works there, try logging the output to a file



15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php >/usr/home/yourlogin/injuries.log

esiason14
04-22-2007, 10:16 AM
Try it from the command line.

Thanks for the quick response. How would I do that ^^

wildjokerdesign
04-22-2007, 10:33 AM
You log into your account via SSH and the putty program and then run the php script. Have you ever done that? The WH manual has a link to putty and some general guidelines on setting it up and logging in. The actual command in putty you would run is.

php /var/www/cgi-bin/getinjuries.php

I also do not think that in your corn job you need to supply the path to php but not 100% sure on that.

wildjokerdesign
04-22-2007, 10:35 AM
Here is the link to the WH manual area on SSH
http://www.helpdocs.westserver.net/sitemanager/SSH_Software.htm

esiason14
04-22-2007, 01:16 PM
Ok, yes...I have done that and it does run. Also if I run it from a browser it runs fine too. So I guess I have to set up a log to find out where the cron is dying. Can you help me out with that as well?

wildjokerdesign
04-22-2007, 03:50 PM
All you need to do is add this to the end of the line as Richard has indicated:

>/usr/home/yourlogin/injuries.log

wildjokerdesign
04-22-2007, 04:09 PM
I was going back looking at some of the old post on this subject to refresh my memory and one thing I found is that a user was having problems because the php script they where running had relative paths in it. So that is something you might want to check in your php script.
Reference: http://forums.westhost.com/showthread.php?t=9178

esiason14
04-22-2007, 07:16 PM
wildjokerdesign, thanks for taking the time to check into this. That did it. I tested it out and it's finally working!! Thanks again!

rolling
04-23-2007, 04:18 PM
The actual command in putty you would run is.

php /var/www/cgi-bin/getinjuries.php

I also do not think that in your corn job you need to supply the path to php but not 100% sure on that.
It is vital that you use the same path in your test and the Cron job.

Jobs which are run by cron do not run in the same environment as us mere mortals, since it does not log in. It is therefore quite possible that environment variables (such as path) are different. For this reason, you should always use absolute paths (/usr/local/bin/php and not just php) in the specification of of your job and in your scripts.