分类: 系统运维
2007-06-27 13:21:54
#!/bin/sh
#Jiu Bu Gai Two Sheel.
#All OK=0,CNC OK=1,TELE OK=2,All Down=3
_PATH="/etc"
tele_gw="219.149.167.225"
cnc_gw="60.220.248.137"
log=/var/log/hand.log
OK=60
while [ "$OK" ]
do
cnc=`ping -c5 $cnc_gw | grep received | cut -d ' ' -f 4`
tele=`ping -c5 $tele_gw | grep received | cut -d ' ' -f 4`
if [ $cnc = "0" ] ; then
cnc=`ping -c8 $cnc_gw | grep received | cut -d ' ' -f 4`
fi
if [ $tele = "0" ] ; then
tele=`ping -c8 $tele_gw | grep received | cut -d ' ' -f 4`
fi
if [ -s $_PATH/xian.conf ] ; then
xian=`cat $_PATH/xian.conf`
else
touch $_PATH/xian.conf
fi
if [ "$cnc" != "0" ] && [ "$tele" != "0" ] ; then
if [ "$xian" != "0" ] ; then
echo `date "+DATE: %Y-%m-%d-%H:%M:%S"`------ All up! >> $log
echo 0 >$_PATH/xian.conf
route delete default
route add default $cnc_gw
pfctl -f $_PATH/pf.conf
OK=60
fi
elif [ "$cnc" != "0" ] ; then
if [ "$xian" != "1" ] ; then
echo `date "+DATE: %Y-%m-%d-%H:%M:%S"`------ Only Cnc up! >> $log
echo 1 >$_PATH/xian.conf
route delete default
route add default $cnc_gw
pfctl -f $_PATH/cnc.conf
fi
OK=60
elif [ "$tele" != "0" ] ; then
if [ "$xian" != "2" ] ; then
echo `date "+DATE: %Y-%m-%d-%H:%M:%S"`------ Only Tele up! >> $log
echo 2 >$_PATH/xian.conf
route delete default
route add default $tele_gw
pfctl -f $_PATH/tele.conf
fi
OK=60
else
if [ "$xian" != "3" ] ; then
echo `date "+DATE: %Y-%m-%d-%H:%M:%S"`------ All Down! >> $log
echo 3 >$_PATH/xian.conf
OK=1
fi
fi
sleep $OK
done
|