【问题标题】:Crontab - sh: ip command not foundcrontab - sh: 找不到 ip 命令
【发布时间】:2014-08-01 06:13:32
【问题描述】:

我有一个php脚本,可以成功得到这个命令的结果。

exec("ip addr list",$results);

如果我在命令行上使用

/usr/bin/php /root/myscript.php

但是当 crontab 让它运行时,它会导致 sh: ip command not found。 我也试过了

exec("/sbin/ip addr list",$results);

但仍然没有运气

任何帮助将不胜感激。

【问题讨论】:

    标签: linux networking centos ip crontab


    【解决方案1】:

    将日志添加到您的 cronjob 以查看可能出现的问题,例如;

    # m h  dom mon dow   command
    14 9 1 8 * /usr/bin/php /home/user/test.php >> /home/user/test.log 2>&1
    

    以下代码通过 cronjob 成功执行;

    <?php
    $ret = exec("/sbin/ip addr list", $out, $err);
    $file = '/home/user/output.log';
    file_put_contents($file, $out);
    ?>
    

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2019-08-10
      • 1970-01-01
      • 2021-01-14
      • 2021-11-13
      • 2019-04-19
      • 2013-05-16
      • 2018-08-10
      • 1970-01-01
      相关资源
      最近更新 更多