expect: telnet2switch

#!/usr/bin/expect                                                                                                                    

if {$argc != 1} {
  puts "usage: ./telnet2sswitch <r2|r3>"
  exit                                                               
}                                                                    

if {"[lindex $argv 0]" == "r0"} {set ip 192.168.130.10 }
if {"[lindex $argv 0]" == "r1"} {set ip 192.168.130.11 }             
if {"[lindex $argv 0]" == "r2"} {set ip 192.168.130.12 }             
if {"[lindex $argv 0]" == "r3"} {set ip 192.168.130.13 }             

user=admin
passwd=xxx
                                                                     
spawn telnet $ip                                                                                                                            
expect "Login:" {send "$user\r"}                                                                                                            
expect "Password:" {send "$passwd\r"}                                                                                                   
                                                                     
interact 
posted @ 2022-11-09 10:38  武平宁  阅读(21)  评论(0)    收藏  举报