Chinaunix首页 | 论坛 | 博客
  • 博客访问: 83417
  • 博文数量: 12
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-08 23:23
文章分类

全部博文(12)

文章存档

2010年(1)

2008年(1)

2007年(10)

我的朋友

分类: 系统运维

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

文件: hand.tar.gz
大小: 0KB
下载: 下载

阅读(4346) | 评论(1) | 转发(0) |
0

上一篇:IP工具

下一篇:爬和撞 (鲁迅)

给主人留下些什么吧!~~

chinaunix网友2010-04-02 10:52:39

请问这个双线切换脚本怎么用?