2013-07-24 179 views
1

我有一個腳本的問題。Linux Bash腳本使用函數返回

我寫了一個腳本「getip.sh」,每小時會調用一次。該腳本獲取當前本地IP,並調用了wget如果我手動調用腳本./getip.sh一切工作只是罰款發送該IP地址這樣

http://example.com/index.php?localip=192.168.0.1

。 如果此腳本獲取可以通過crontab叫:

* * * * * cd /home/pi && ./getip.sh >> /home/pi/myLog 

的Web服務器只接收以下 http://example.com/index.php?localip=

任何人都知道這個問題?

#!/bin/bash 

html="http://example.com/index.php?localip="; 
netip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`; 
netcomp=$html$netip; 
wget -O /dev/null -q $netcomp 
echo $netcomp 

回答

4

的cron的路徑不包括/ sbin目錄。使用完整路徑來調用ifconfig:

netip=`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`; 
0

你有沒有測試是這樣的:

* * * * * /home/pi/getip.sh >> /home/pi/myLog