linux系统网络状态查询

var=$(cat/sys/class/net/eth0/carrier)
var1="0"
SLEEPTIME=1
while :;do
var=$(cat/sys/class/net/eth0/carrier)
if [ "$var" == "1"];then
if [ "$var" != "$var1"];then
touch/tmp/netok 
echo "networkchange ok "
busybox udhcpc -s/etc/init.d/udhcpc.script &
fi
var1=$var
elif [ "$var" == "0"];then
var=$(cat/sys/class/net/wlan0/carrier)
if [ "$var" == "1"];then
if [ "$var" != "$var1"];then
echo "wifi change ok"
touch/tmp/netok 
busybox udhcpc -s/etc/init.d/udhcpc.script &
fi
elif [ "$var" == "0"];then
if [ -f"/tmp/netok" ]; then
echo "eth and wifi all NG "
rm -rf/tmp/netok 
fi
fi
var1=$var
fi
#echo "At `date +'%F %T'`"
sleep $SLEEPTIME
done
var=$(cat /sys/class/net/eth0/carrier)var1="0"SLEEPTIME=1while :;dovar=$(cat /sys/class/net/eth0/carrier)if [ "$var" == "1" ];thenif [ "$var" != "$var1" ];thentouch /tmp/netok echo "network change  ok "busybox udhcpc -s /etc/init.d/udhcpc.script &fivar1=$varelif [ "$var" == "0" ];thenvar=$(cat /sys/class/net/wlan0/carrier)if [ "$var" == "1" ];thenif [ "$var" != "$var1" ];thenecho "wifi change ok "touch /tmp/netok busybox udhcpc -s /etc/init.d/udhcpc.script &fielif [ "$var" == "0" ];then

if [  -f "/tmp/netok" ]; thenecho "eth and wifi all NG "rm -rf /tmp/netok fifivar1=$varfi

#echo "At `date +'%F %T'` "

sleep $SLEEPTIMEdone
(0)

相关推荐