ping_status() { for var in 1 2 3; do if ping -c 1 $IP > /dev/null; then #echo "$IP Ping is successful." return 0 else #echo "$IP Ping is failure" if [ $var -eq 3 ]; then return 1 fi fi done }
whiletrue do ping_status if [ $? -ne 0 ]; then case$statein 0) #echo "wan to wwan" if uci get network.wwan > /dev/null; then uci set network.wwan.metric=0 fi if uci get network.wan > /dev/null; then uci set network.wan.metric=20 fi
if uci get network.4G > /dev/null; then uci set network.4G.metric=10 fi ;; 1) #echo "wwan to 4G" if uci get network.wwan > /dev/null; then uci set network.wwan.metric=20 fi if uci get network.wan > /dev/null; then uci set network.wan.metric=10 fi
if uci get network.4G > /dev/null; then uci set network.4G.metric=0 fi ;; 2) #echo "4G to wan" if uci get network.wwan > /dev/null; then uci set network.wwan.metric=10 fi if uci get network.wan > /dev/null; then uci set network.wan.metric=0 fi
if uci get network.4G > /dev/null; then uci set network.4G.metric=20 fi ;; esac
uci commit network; /etc/init.d/network reload; let state++ if [ ${state} -ge 3 ]; then state=0 fi fi sleep 10