博达交换机镜像检查,镜像丢失自动添加脚本
check_bd_mirr.sh
#!/bin/bash
#/home/tools/check_tools/cfg_bd_mirror/check_bd_mirr.sh #所在目录文件名
process_day=`date -d today +"%Y-%m-%d %H:%M:%S"`
process_day=`date -d today +"%Y-%m-%d %H:%M:%S"`
cd /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak
rm -rf 10.230.*.cfg
cd /home/tools/check_tools/cfg_bd_mirror/
./telnet_bdcom.sh
#cfg_mir=$(cat /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*10.230.87.221*.cfg |grep -E "mirror session 1 source")
cfg_mir=$(cat /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*`date -d today +"%Y%m%d"`*.cfg |grep -E "mirror session 1 source")
ip_add=$(ls /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*10.230.87.221*.cfg |awk -F "-" '{print $2}')
rm -rf 10.230.*.cfg
cd /home/tools/check_tools/cfg_bd_mirror/
./telnet_bdcom.sh
#cfg_mir=$(cat /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*10.230.87.221*.cfg |grep -E "mirror session 1 source")
cfg_mir=$(cat /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*`date -d today +"%Y%m%d"`*.cfg |grep -E "mirror session 1 source")
ip_add=$(ls /home/tools/check_tools/cfg_bd_mirror/Bdcom_bak/*10.230.87.221*.cfg |awk -F "-" '{print $2}')
if [[ -z $cfg_mir ]] ;
then
echo ${process_day} "no mirror"
./cfg_bd_mir.sh
else
echo ${process_day} "mirror OK"
fi
then
echo ${process_day} "no mirror"
./cfg_bd_mir.sh
else
echo ${process_day} "mirror OK"
fi
telnet_bdcom.sh
#!/bin/bash
#/home/tools/check_tools/cfg_bd_mirror/telnet_bdcom.sh #所在目录文件名
datetime=`date +%Y%m%d`
BAKTIME=`date +%Y%m%d%H%M%S`
user="admin"
password="123456"
back1="enable"
back2="config"
back3="show runn"
BAK_DIR=/home/tools/check_tools/cfg_bd_mirror/Bdcom_bak
#mkdir $BAK_DIR
for i in $(cat bdcom_ip_file)
datetime=`date +%Y%m%d`
BAKTIME=`date +%Y%m%d%H%M%S`
user="admin"
password="123456"
back1="enable"
back2="config"
back3="show runn"
BAK_DIR=/home/tools/check_tools/cfg_bd_mirror/Bdcom_bak
#mkdir $BAK_DIR
for i in $(cat bdcom_ip_file)
do
{
echo $user;
echo $user;
sleep 1;
echo $password;
sleep 1;
echo $back1;
sleep 1;
echo $back2;
sleep 1;
echo $back3;
sleep 1;
echo "
";
";
sleep 5;
}|telnet $i > $BAK_DIR/$i-$BAKTIME.cfg
tail -n +18 $BAK_DIR/$i.cfg > $BAK_DIR/$i.cfg
rm -rf $BAK_DIR/$i.cfg
done
tail -n +18 $BAK_DIR/$i.cfg > $BAK_DIR/$i.cfg
rm -rf $BAK_DIR/$i.cfg
done
cfg_bd_mir.sh
#!/bin/bash
#/home/tools/check_tools/cfg_bd_mirror/cfg_bd_mir.sh #所在目录文件名
datetime=`date +%Y%m%d`
BAKTIME=`date +%Y%m%d%H%M%S`
user="admi"
password="123456"
back1="enable"
back2="config"
back3="mirror session 1 source interface gigaEthernet 0/1 - 32 rx"
back4="mirror session 1 source interface gigaEthernet 0/33 - 44 rx"
back5="mirror session 1 destination interface g0/48"
back6="int g0/13"
back7="int g0/14"
back8="int g0/25"
back9="int g0/26"
back10="shutdown"
back11="no shutdown"
back12="show runn"
BAK_DIR=/home/tools/check_tools/cfg_bd_mirror/Bdcom_bak
mkdir $BAK_DIR
for i in $(cat bdcom_ip_file)
datetime=`date +%Y%m%d`
BAKTIME=`date +%Y%m%d%H%M%S`
user="admi"
password="123456"
back1="enable"
back2="config"
back3="mirror session 1 source interface gigaEthernet 0/1 - 32 rx"
back4="mirror session 1 source interface gigaEthernet 0/33 - 44 rx"
back5="mirror session 1 destination interface g0/48"
back6="int g0/13"
back7="int g0/14"
back8="int g0/25"
back9="int g0/26"
back10="shutdown"
back11="no shutdown"
back12="show runn"
BAK_DIR=/home/tools/check_tools/cfg_bd_mirror/Bdcom_bak
mkdir $BAK_DIR
for i in $(cat bdcom_ip_file)
do
{
echo $user;
echo $user;
sleep 1;
echo $password;
sleep 1;
echo $back1;
sleep 1;
echo $back2;
sleep 1;
echo $back3;
sleep 1;
echo $back4;
sleep 1;
echo $back5;
sleep 1;
echo $back6;
sleep 1;
echo $back10;
sleep 1;
echo $back11;
sleep 1;
echo $back7;
sleep 1;
echo $back10;
sleep 1;
echo $back11;
sleep 1;
echo $back8;
sleep 1;
echo $back10;
sleep 1;
echo $back11;
sleep 1;
echo $back9;
sleep 1;
echo $back10;
sleep 1;
echo $back11;
sleep 1;
echo $back12;
sleep 1;
echo "
";
";
sleep 5;
}|telnet $i > $BAK_DIR/$i-$BAKTIME.log
tail -n +18 $BAK_DIR/$i-$BAKTIME.log > $BAK_DIR/MY-$i-$BAKTIME.log
rm -rf $BAK_DIR/$i-$BAKTIME.log
done
tail -n +18 $BAK_DIR/$i-$BAKTIME.log > $BAK_DIR/MY-$i-$BAKTIME.log
rm -rf $BAK_DIR/$i-$BAKTIME.log
done