Bash命令没有执行时通过cron作业 - PHP [英] Bash commands not executed when through cron job - PHP

查看:189
本文介绍了Bash命令没有执行时通过cron作业 - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cron作业每五分钟运行一个PHP脚本; PHP脚本在脚本结尾处执行两个bash命令。我知道脚本正在运行,由于它附加的日志文件。当我通过Ubuntu Gnome终端手动运行PHP脚本时,两个bash命令执行完美;但是当PHP脚本通过cron触发时,两个bash命令不会运行。有任何想法吗?

  $ command ='notify-send''count($ infoleakPosts)。 
`$ command`;

$ command ='firefox http://example.com';
`$ command`;

* / 1 * * * * php /home/andrew/grab.php USERNAME PASSWORD#JOB_ID_1


通常,您的cron脚本将在不同的用户帐户下运行,并且可能设置了不同的环境路径。



尝试设置命令行以使用命令的完整路径,即。 / path / to / notify-sendx New Posts



您可以使用



您也可以从命令中获取输出。

您可以从您的常规终端获取通知发送
以帮助调试。

  $ output =`$ command`; 
error_log($ output);


I have a cron job running a PHP script every five minutes; the PHP script executes two bash commands at the end of the script. I know the script is running due to a log file it appends to. When I run the PHP script manually via the Ubuntu Gnome Terminal both bash commands execute flawlessly; however when the PHP script is triggered via cron, the two bash commands are not ran. Any ideas?

$command = 'notify-send "' . count($infoleakPosts) . '  New Posts."';
`$command`;

$command = 'firefox http://example.com';
`$command`;

*/1 * * * * php /home/andrew/grab.php USERNAME PASSWORD # JOB_ID_1

解决方案

Generally your cron scripts are going to be run under a different user account, and probably have a different environment path set up.

Try setting your command lines to use the full path to the command, ie. /path/to/notify-send "x New Posts".

You can use which notify-send from your regular terminal to get the path to put into your script.

You can also grab the output from your command to help debugging. Use of the backtick operator will return the output, so you can assign it to a variable and/or dump it.

$output = `$command`;
error_log($output);

这篇关于Bash命令没有执行时通过cron作业 - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆