cisco 交换机 定期 自动 备份配置 -linux,网络设备(思科,华为交换机、路由器)自动备份配置脚本(示例代码)...

#! /bin/bash

tftp_server=10.10.10.10 #tftp-server 服务器,用于存储备份文件

tftp_dir=/var/lib/tftpboot #根目录

back_dir=`date +"%Y%m%d"` #以时间名称备份

mkdir /var/lib/tftpboot/$back_dir

echo "tftp_server_ip 10.10.10 , backup_dir /var/lib/tftpboot/" >> $PWD/result

echo "#### $back_dir huawei-sw backup begin ####" >> $PWD/result

for ip in `cat $PWD/huawei.list` #华为的list

do

ping -c 2 $ip &>2 >/dev/null

/usr/bin/expect <

set timeout 5

spawn telnet $ip

expect "*Username:"

send "admin\r"

expect "*Password:"

send "* * * * * \r"

expect "*>"

send "tftp $tftp_server put vrpcfg.zip $ip.zip\r"

set timeout 10

expect " *second(s)."

send "quit\r"

EOF

sleep 1s

echo "$ip" >> $PWD/result

done

mv /var/lib/tftpboot/*.zip /var/lib/tftpboot/$back_dir #t移动

echo "#### $back_dir huawei-sw backup end ####" >> $PWD/result

echo "#### $back_dir cisco-sw backup begin ####" >> $PWD/result

for cip in `cat $PWD/cisco.list` #思科list

do

ping -c 2 $cip &>2 >/dev/null

/usr/bin/expect <

set timeout 5

spawn telnet $cip

expect "*Username:"

send "admin\r"

expect "*Password:"

send "xxxxxxx\r"

expect "*>"

send "en\r"

expect "*Password:"

send "xxxxxxxx\r"

send "copy startup-config tftp:\r"

send "$tftp_server\r"

send "$cip\r"

set timeout 10

send "exit\r"

expect EOF

EOF

echo "$cip" >> $PWD/result

done

mv /var/lib/tftpboot/10.* /var/lib/tftpboot/$back_dir

echo "#### $back_dir cisco-sw backup end ####" >> $PWD/result

tail -42 result | mailx -v -s "xxxxx-idc sw backup ended | from maboai mail" [email protected],[email protected] # 备份完后发送邮件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值