Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1734028
  • 博文数量: 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-12-23 16:39:50

记录一下
自动批量修改cisco交换机密码

点击(此处)折叠或打开

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

  2. #file name: chswpw.exp
  3. #Usages: batch change switch manager password
  4. #Version: v1.1
  5. #By Create Edward.zhou
  6. #Date: 2012-12-23

  7. set timeout -1

  8. set oldpasswd [lindex $argv 0]
  9. set oldenapwd [lindex $argv 1]
  10. set swhost [lindex $argv 2]
  11. set newpasswd [lindex $argv 3]
  12. set newenapwd [lindex $argv 4]
  13. set newconpwd [lindex $argv 5]

  14. if { $argc <=3 } {
  15. puts "Usage $argv0 passwd enablepasswd switchhost tftpserver\r"
  16. puts "Use Method: ./chswpw.exp oldpasswd oldenapwd swhost newpasswd newenapwd newconpw\r"
  17. exit 1
  18. }

  19. spawn telnet $swhost
  20. expect "Password:"
  21. send "$oldpasswd\r"
  22. expect "*>"
  23. send "enable\r"
  24. expect "Password:"
  25. send "$oldenapwd\r"
  26. expect "*#"
  27. send "conf t\r"
  28. expect "*fig)#"
  29. send "enable secret $newenapwd\r"
  30. expect "*fig)#"
  31. send "line vty 0 4\r"
  32. expect "*line)#"
  33. send "password $newpasswd\r"
  34. send "exit\r"
  35. expect "*fig)#"
  36. send "line con 0\r"
  37. expect "*line)#"
  38. send "password $newconpwd\r"
  39. send "exit\r"
  40. send "end\r"
  41. expect "*fig)#"
  42. send "wr\r"
  43. send "end\r"
  44. send "exit\r"
  45. send "\r"
  46. #interact


阅读(4170) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~