0

我正在尝试点击 PHP url 并使用 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

有人可以告诉我如何正确传递参数吗?

4

3 回答 3

0

您可以从以下位置获取正常运行时间(以秒为单位)/proc/uptime

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

于 2014-02-13T18:04:22.053 回答
0

试试这种方式:

*/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

于 2014-02-13T18:02:50.710 回答
0
 ?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 }'`;
                                                                         ^
于 2014-02-13T18:33:32.297 回答