今天,是linux回炉的第八十六天
shell
我们生产环境下,发现Linux路由无法完成永久写入,不得已只能写个shell
#!/bin/bash
COUNT=`route -n|grep -v ^K|grep -v ^D|wc -l`
if [ $COUNT == 7 ]
then
echo "路由正常"
else
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 1p` == "0.0.0.0" ]
then
echo "网关59.217.9.129启动"
else
route add .NET 0.0.0.0 netmask 0.0.0.0 gw 59.217.9.129
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 2p` == "0.0.0.0" ]
then
echo "网关10.255.30.30启动"
else
route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.255.30.30
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 3p` == "10.0.0.0" ]
then
echo "网关10.255.30.30启动"
else
route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.255.30.30
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 4p` == "10.255.30.0" ]
then
echo "网关0.0.0.0启动"
else
route add -net 10.255.30.0 netmask 255.255.255.0 gw 0.0.0.0
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 5p` == "59.217.0.0" ]
then
echo "59.217.9.129启动"
else
route add -net 59.217.0.0 netmask 255.255.255.0 gw 59.217.9.129
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 6p` == "59.217.9.128" ]
then
echo "0.0.0.0启动"
else
route add -net 59.217.9.128 netmask 255.255.255.128 gw 0.0.0.0
fi
if [ `route -n|awk '{print $1}'|grep -v ^K|grep -v ^D|sed -n 7p` == "192.168.122.0" ]
then
echo "0.0.0.0启动"
else
route add -net 192.168.122.0 netmask 255.255.255.0 gw 0.0.0.0
fi
fi
route -n >route1.txt
diff route.txt route1.txt>route2.txt
DIFF_COUNT=`cat route2.txt|awk '{print $4}'|sed '/^$/d'|grep -v routing|grep -v Genmask|wc -l`
if [ "$DIFF_COUNT" == "0" ];then
echo "diff显示相同"
else
for i in `cat route2.txt|awk '{print $2}'|sed '/^$/d'|grep -v ^K|grep -v ^D`
do
COUNT_MASK=`cat route2.txt|awk '{print $4}'|sed '/^$/d'|grep -v routing|grep -v Genmask|awk '{print $1}'|wc -l`
for ((n=1;n<=$COUNT_MASK;n++))
do
MASK=`cat route2.txt|awk '{print $4}'|sed '/^$/d'|grep -v routing|grep -v Genmask|awk '{print $1}'|sed -n "$n"p`
if [ "$MASK" == "255.255.255.0" ];then
SUBET_MASK=24
route del -net $i/$SUNET_MASK
if [ "echo $?" == 0 ];then
echo "已经关闭IP地址为:"$i
continue
else
2>&1
fi
elif [ "$MASK" == "0.0.0.0" ];then
SUNET_MASK=0
route del -net $i/$SUNET_MASK
if [ "echo $?" == 0 ];then
echo "已经关闭IP地址为:"$i
continue
else
2>&1
fi
elif [ "$MASK" == "255.0.0.0" ];then
SUNET_MASK=8
route del -net $i/$SUNET_MASK
if [ "echo $?" == 0 ];then
echo "已经关闭IP地址为:"$i
continue
else
2>&1
fi
elif [ "$MASK" == "255.255.0.0" ];then
SUNET_MASK=16
route del -net $i/$SUNET_MASK
if [ "echo $?" == 0 ];then
echo "已经关闭IP地址为:"$i
continue
else
2>&1
fi
fi
done
done
fi
fi