记录一下
自动批量修改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
  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


09-13 20:39