[英]Crontab - sh: ip command not found
I have a php script that can successfully get the results of this command. 我有一个PHP脚本,可以成功获取此命令的结果。
exec("ip addr list",$results);
if I run it on command line using 如果我在命令行上使用运行
/usr/bin/php /root/myscript.php
but when crontab will make it run, it will result to sh: ip command not found. 但是当crontab使它运行时,将导致sh:ip命令未找到。 i also tried
我也尝试过
exec("/sbin/ip addr list",$results);
but still no luck 但仍然没有运气
Any help would be greatly appreciated. 任何帮助将不胜感激。
Add a log to your cronjob to see what might go wrong, eg; 在您的cronjob中添加日志,以查看可能出了什么问题。
# m h dom mon dow command
14 9 1 8 * /usr/bin/php /home/user/test.php >> /home/user/test.log 2>&1
Below code got executed successfully with a cronjob; 下面的代码通过cronjob成功执行;
<?php
$ret = exec("/sbin/ip addr list", $out, $err);
$file = '/home/user/output.log';
file_put_contents($file, $out);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.