【问题标题】:execute php file, then email and log output执行 php 文件,然后发送电子邮件并记录输出
【发布时间】:2020-01-07 14:06:04
【问题描述】:

我有一个 cron 作业,我想执行一个 PHP 文件,然后获取输出和电子邮件并保存到日志文件中。

我可以用这个发邮件:

/path/to/php /path/to/script.php | mail -s "script results" my@email.com

我可以使用它来保存到日志文件:

/path/to/php /path/to/script.php >> /path/to/logfile.log 2>&1

但这并不像我预期的那样对我有用:

/path/to/php /path/to/script.php | mail -s "script results" my@email.com >> /path/to/logfile.log 2>&1

它似乎正在通过电子邮件发送输出,但没有写入日志文件。

我正在运行 Ubuntu 16.04。

【问题讨论】:

  • @user3783243 网络主机设置服务器的方式使这变得复杂。

标签: php cron command-line-interface ubuntu-16.04


【解决方案1】:

您要查找的是tee 命令。

你可以这样做

/path/to/php /path/to/script.php 2>&1 | tee -a /path/to/logfile.log | mail -s "script results" my@email.com

See more about tee

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 2011-07-24
    • 2022-10-15
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    相关资源
    最近更新 更多