How can I run a cron job with arguments and pass results to a log?

我的未来我决定 提交于 2019-12-05 18:14:32

问题


Example:

* * * * * /usr/bin/php /full/path/to/script.php arg1 arg2 > /full/path/to/logfile.log

The script runs and accesses the arguments just fine, but the results are never printed to the logfile.log. Also, my logfile.log is chmod 777, so I know it has write access.

Can you fix my syntax?


回答1:


It looks like you are searching for the log file in the wrong folder. Try this

* * * * * cd /path/to/script.php ; ./script.php arg1 arg2 >> logfile.log

Then look for your log file in the /path/to/script folder. It can also be a write permission problem. Also, check your script for errors. Your crontab command seems OK.




回答2:


Does the command work correctly from the command line? It may be possible that the arguments contain some characters treated specially by shell. In that case you need to quote the whole command to prevent shell from tinkering with the arguments.



来源:https://stackoverflow.com/questions/7858114/how-can-i-run-a-cron-job-with-arguments-and-pass-results-to-a-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!