#! /bin/bash
echo "BOTH" > /tmp/route_flag
GW1="platinum.3322.org"
GW2="platinum.net.cn"
while :;
do
FLAG="0"
if ping -c1 -wa $GW1 &>/dev/null; then
FLAG=`expr 1 + $FLAG`
fi
if ping -c1 -wa $GW2 &>/dev/null; then
FLAG=`expr 2 + $FLAG`
fi
case "$FLAG" in
0)
echo "NONE" > /tmp/route_flag
;;
1)
if [ "`cat /tmp/route_flag`" != "GW1" ]; then
echo "使用 GW1 做路由"
echo "GW1" > /tmp/route_flag
fi
;;
2)
if [ "`cat /tmp/route_flag`" != "GW2" ]; then
echo "使用 GW2 做路由"
echo "GW2" > /tmp/route_flag
fi
;;
3)
if [ "`cat /tmp/route_flag`" != "BOTH" ]; then
echo "使用双路由"
echo "BOTH" > /tmp/route_flag
fi
;;
esac
sleep 5
done
|