原理是采用tcl expect方式自动备份文件到tftp服务器(采用atftp,tftp-hpa都可)
脚本如下
cat backsw-.1.2.exp
- #!/usr/bin/expect -f
- #file name: baksw.exp
- #Usages: auto backup switch configure
- #Version: v1.2
- #By Create Edward.zhou
- #Date: 2012-07-14
- set timeout -1
- if { $argc !=4 } {
- puts "Usage $argv0 passwd enablepasswd switchhost tftpserver"
- exit 1
- }
- set passwd [lindex $argv 0]
- set enapwd [lindex $argv 1]
- set swhost [lindex $argv 2]
- set tftpsr [lindex $argv 3]
- spawn telnet $swhost
- expect "Password:"
- send "$passwd\r"
- expect "*>"
- send "enable\r"
- expect "Password:"
- send "$enapwd\r"
- expect "*#"
- send "copy startup-config tftp:\r"
- expect "*]?"
- send "$tftpsr\r"
- expect "*]?"
- send "\r"
- send "exit\r"
- interact
使用方式: backsw-1.2.exp *** *** 10.1.11.1 10.1.10.8
缺点: 只能单独备份一台设备
阅读(2970) | 评论(0) | 转发(0) |