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

Rya*_*yan 10 unix linux cron crontab

例:

* * * * * /usr/bin/php /full/path/to/script.php arg1 arg2 > /full/path/to/logfile.log
Run Code Online (Sandbox Code Playgroud)

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

你能修复我的语法吗?

mik*_*mik 12

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

* * * * * cd /path/to/script.php ; ./script.php arg1 arg2 >> logfile.log
Run Code Online (Sandbox Code Playgroud)

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