简体   繁体   English

使用wget将数据发送到php

[英]Sending data to php using wget

I am trying to hit a PHP url and post some information about my linux box using a cron job and wget. 我正在尝试访问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 }`;

on php side i am tryint to get request parameters like mac, uptime and ip but i am only able to record mac. 在PHP方面,我是tryint来获取诸如mac,uptime和ip之类的请求参数,但我只能记录mac。 Reason i think is because uptime command has 23:42:10 up 22 min, load average: 0.00, 0.01, 0.04 as output which may be breaking the wget process. 我认为的原因是因为正常运行时间命令具有23:42:10 up 22 min, load average: 0.00, 0.01, 0.04作为输出,这可能会中断wget进程。 I am getting following message when i run wget 运行wget时出现以下消息

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

Can someone please tell me how to pass parameters correctly? 有人可以告诉我如何正确传递参数吗?

Try it this way: 尝试这种方式:

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

You are putting /dev/null where wget expects the url, you just have to switch /dev/null and the url 您将/ dev / null放在wget期望URL的位置,只需切换/ dev / null和URL

您可以从/proc/uptime以秒为单位获取正常/proc/uptime

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

 ?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 }'`;
                                                                         ^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM