Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1730817
  • 博文数量: 234
  • 博客积分: 4966
  • 博客等级: 上校
  • 技术积分: 3322
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-13 01:03
文章分类

全部博文(234)

文章存档

2017年(2)

2016年(1)

2015年(8)

2014年(11)

2013年(44)

2012年(27)

2011年(22)

2010年(30)

2009年(37)

2008年(6)

2007年(45)

2006年(1)

分类: LINUX

2012-07-13 15:46:31

原理是采用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
缺点: 只能单独备份一台设备
阅读(2890) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~