脚本如下
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
缺点: 只能单独备份一台设备