开发者

script runs fine when run from command line but not via cron

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

however the php script doesn't se开发者_如何学Goem to run even though a cron job set to run it every 10 minutes.

How do I view errors produced by cron job ?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜