2014-02-13 59 views
0

我想要打開一個PHP網址併發布一些關於我的linux盒子使用cron作業和wget的信息。使用wget發送數據到php

*/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的身邊,我很tryint得到請求參數,如MAC,正常運行時間和IP,但我只能夠記錄MAC。我認爲的原因是因爲正常運行時間命令有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 

有人可以請告訴我如何正確傳遞參數?

回答

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的預期網址,你只需要切換的/ dev/null,並且網址

0

你可以得到正常運行時間從/proc/uptime秒:

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

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