自动批量修改cisco交换机密码
点击(此处)折叠或打开
- #!/usr/bin/expect -f
- #file name: chswpw.exp
- #Usages: batch change switch manager password
- #Version: v1.1
- #By Create Edward.zhou
- #Date: 2012-12-23
- set timeout -1
- set oldpasswd [lindex $argv 0]
- set oldenapwd [lindex $argv 1]
- set swhost [lindex $argv 2]
- set newpasswd [lindex $argv 3]
- set newenapwd [lindex $argv 4]
- set newconpwd [lindex $argv 5]
- if { $argc
- puts "Usage $argv0 passwd enablepasswd switchhost tftpserver\r"
- puts "Use Method: ./chswpw.exp oldpasswd oldenapwd swhost newpasswd newenapwd newconpw\r"
- exit 1
- }
- spawn telnet $swhost
- expect "Password:"
- send "$oldpasswd\r"
- expect "*>"
- send "enable\r"
- expect "Password:"
- send "$oldenapwd\r"
- expect "*#"
- send "conf t\r"
- expect "*fig)#"
- send "enable secret $newenapwd\r"
- expect "*fig)#"
- send "line vty 0 4\r"
- expect "*line)#"
- send "password $newpasswd\r"
- send "exit\r"
- expect "*fig)#"
- send "line con 0\r"
- expect "*line)#"
- send "password $newconpwd\r"
- send "exit\r"
- send "end\r"
- expect "*fig)#"
- send "wr\r"
- send "end\r"
- send "exit\r"
- send "\r"
- #interact