如何使用参数运行cron作业并将结果传递给日志?

时间:2011-10-22 07:45:29

标签: linux unix cron crontab

示例:

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

脚本运行并访问参数就好了,但结果永远不会打印到logfile.log中。另外,我的logfile.log是chmod 777,所以我知道它有写访问权。

你能修复我的语法吗?

2 个答案:

答案 0 :(得分:11)

看起来您正在错误的文件夹中搜索日志文件。 试试这个

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

然后在/ path / to / script文件夹中查找您的日志文件。 它也可能是写权限问题。 另外,检查脚本是否有错误。 您的crontab命令似乎没问题。

答案 1 :(得分:1)

命令是否可以从命令行正常运行? 参数可能包含一些由shell专门处理的字符。在这种情况下,您需要引用整个命令以防止shell修改参数。

相关问题