tags:

views:

254

answers:

3

i have a php script which runs fine when executed by SSHing into my server and running it.

however the php script doesn't seem to run even though a cron job set to run it every 10 minutes.

How do I view errors produced by cron job ?

A: 

not sure but it's probably credentials related. Schedule your task to run with your user ID and see if that doesn't clear it up. If so, you'll need to create a set of "batch" credentials that you can use to schedule tasks to run beneath.

No Refunds No Returns
+1  A: 

Sometimes, the error messages are emailed to you by cron. Otherwise, it probably gets sent to a hapless system administrator who probably scrupulously saves the messages in /dev/null.

When things work from the command line and do not work from cron, the 'environment' is almost always at fault. Something that is set in the normal command line environment is not set in the cron environment. Remember, cron does not run your profile for you - you have a bare minimal set of environment variables with bare minimum values for things like PATH.

Generally, I assume that I should run a shell script from cron, and that shell script is responsible for ensuring the correct environment is in place - and that errors are trapped and logged appropriately - before running the main part of the software.

Jonathan Leffler
+1  A: 

Remember that cron runs your script in a different working directory than what you're probably used to. Try something like the following on the command line:

cd /
./path/to/your/script.php

If it fails, modify all paths in your script correctly until it runs. Then it will run in cron.

slebetman