【问题标题】:Sending data to php using wget使用 wget 向 php 发送数据
【发布时间】:2014-02-13 17:55:30
【问题描述】:

我正在尝试访问 PHP 网址并使用 cron 作业和 wget 发布有关我的 linux 机器的一些信息。

*/30 * * * * wget -O /dev/null http://ping.xxx.com/xxx/up.php?mac=`ifconfig eth1 | awk '/HWaddr/ { print $5 }`\&uptime=`uptime`\&ip=`ifconfig eth1 | awk '/inet addr:/ {sub(/addr:/, "", $2); print $2 }`;

在 php 方面,我正在尝试获取 mac、uptime 和 ip 等请求参数,但我只能记录 mac。我认为的原因是因为 uptime 命令有 23:42:10 up 22 min, load average: 0.00, 0.01, 0.04 作为输出,这可能会破坏 wget 进程。运行 wget 时收到以下消息

wget: not an http or ftp url: 23:42:10

谁能告诉我如何正确传递参数?

【问题讨论】:

    标签: php linux unix wget uptime


    【解决方案1】:

    试试这个方法:

    */30 * * * * wget -O http://ping.xxx.com/xxx/up.php?mac=`ifconfig eth1 | awk '/HWaddr/ { print $5 }`\&uptime=`uptime`\&ip=`ifconfig eth1 | awk '/inet addr:/ {sub(/addr:/, "", $2); print $2 }` /dev/null;
    

    您将 /dev/null 放在 wget 期望 url 的位置,您只需切换 /dev/null 和 url

    【讨论】:

      【解决方案2】:

      您可以从/proc/uptime 获得以秒为单位的正常运行时间:

      cut -d " " -f 1 /proc/uptime

      【讨论】:

        【解决方案3】:
         ?mac=`ifconfig eth1 | awk '/HWaddr/ { print $5 }`
        \&uptime=`uptime`
        \&ip=`ifconfig eth1 | awk '/inet addr:/ {sub(/addr:/, "", $2); print $2 }`;
        
        Add quotes
                                                         V
         ?mac=`ifconfig eth1 | awk '/HWaddr/ { print $5 }'`
        \&uptime=`uptime`
        \&ip=`ifconfig eth1 | awk '/inet addr:/ {sub(/addr:/, "", $2); print $2 }'`;
                                                                                 ^
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-03-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-01-22
          • 1970-01-01
          • 2013-10-11
          相关资源
          最近更新 更多