原理是采用tcl expect方式自动备份文件到tftp服务器(采用atftp,tftp-hpa都可)
脚本如下
cat backsw-.1.2.exp

点击(此处)折叠或打开

  1. #!/usr/bin/expect -f

  2. #file name: baksw.exp
  3. #Usages: auto backup switch configure
  4. #Version: v1.2
  5. #By Create Edward.zhou
  6. #Date: 2012-07-14

  7. set timeout -1

  8. if { $argc !=4 } {
  9. puts "Usage $argv0 passwd enablepasswd switchhost tftpserver"
  10. exit 1
  11. }

  12. set passwd [lindex $argv 0]
  13. set enapwd [lindex $argv 1]
  14. set swhost [lindex $argv 2]
  15. set tftpsr [lindex $argv 3]
  16. spawn telnet $swhost
  17. expect "Password:"
  18. send "$passwd\r"
  19. expect "*>"
  20. send "enable\r"
  21. expect "Password:"
  22. send "$enapwd\r"
  23. expect "*#"
  24. send "copy startup-config tftp:\r"
  25. expect "*]?"
  26. send "$tftpsr\r"
  27. expect "*]?"
  28. send "\r"
  29. send "exit\r"
  30. interact



使用方式:  backsw-1.2.exp *** *** 10.1.11.1 10.1.10.8
缺点: 只能单独备份一台设备
09-13 20:27