在管道到文件时输出 php 标头的 cron 作业



我有一个bash脚本,它运行4个命令并重定向到一个文件。当我自己从服务器上的 CLI 运行它时,此脚本工作正常。当我让 cron 运行脚本时,它不起作用。

我的文件看起来像这样:

#!/bin/bash
command > file.csv
command >> file.csv
command >> file.csv
command >> file.csv

当我自己运行它时,我得到了预期的结果,但是当 cron 运行它时,我得到这个:

X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8

我像这样执行 cron 作业:

/usr/bin/php -q /home/user/rest/of/path/script.sh >/dev/null

有人可以帮忙吗?快把我逼疯了....

解决方案是在 bash 脚本中指定 PATH 属性。

我在 shell 中回显了 $PATH 变量并将其复制到脚本中,这似乎解决了问题。

最新更新