sszxf 发表于 2018-7-25 10:36:29

网络设备(思科,华为交换机、路由器)自动备份配置脚本

#! /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 <<-EOF   #调用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 <<-EOF
  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 -42result | mailx -v -s "xxxxx-idc sw backup ended | from maboai mail" xxxxxx@163.com,xxxxxx@163.com      #备份完后发送邮件
页: [1]
查看完整版本: 网络设备(思科,华为交换机、路由器)自动备份配置脚本