how to monitor Internet connection status

ref:https://unix.stackexchange.com/questions/251625/how-to-log-internet-connection-drops

       

while :
do
        for interface in $(ls /sys/class/net/ | grep -v lo | grep -v p2p0| grep -v wlan0);
        do
                status=$( /bin/cat /sys/class/net/"${interface}"/carrier )
                if [ $status == 1 ]; then
                        if [ $eth0_old_status == 0 ]; then
                                eth0_old_status=1
                                udhcpc -i "${interface}"
                        else
                                echo "${interface} already connected"
                        fi
                fi
 
        done
        sleep 10
done

猜你喜欢

转载自blog.csdn.net/u011028408/article/details/81873802