dongyi8416 2013-08-26 10:15
浏览 110

结果表单crontab与手动执行不一样?

I have a PHP script that execute some shell commands.

Once I manually executed it. It worked very fine.

But after I used crontab to execute, the result from some shell commands are missing.

These are 2 commands.

  • ip route
  • iptables -t nat -L | grep 8800

and here is a sample PHP code.

#!/usr/bin/php -q
<?
    $route = exec('ip route');
    $iptable = exec('iptables -t nat -L | grep 8800');
    echo $route;
    echo $iptables;
?>

The above code worked well with manually execute but not crontab.

I found that some commands worked well with both. For example

  • ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
  • cat /tmp/example | grep test

Any ideas for this problem, and thank you in advance.

  • 写回答

2条回答 默认 最新

  • douyun1546 2013-08-26 10:21
    关注

    Pay attention to what user runs the script. May be the user (which you add crontab task) haven't got enough permissions.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数