Posted to tcl by aspect at Thu Apr 02 23:42:52 GMT 2015view raw
- #!/usr/bin/expect -f
- set timeout 30
- spawn telnet {*}$argv
- match_max 100000
- # handle early disconnections
- expect_after {
- eof {
- error "Unexpected end of file!"
- }
- timeout {
- error "Server took too long to respond!"
- }
- }
- # try multiple passwords:
- set passwords {"Pass1" "" "Pass3" "Pass4"}
- set idx -1
- while {1} {
- incr idx
- if {$idx >= [llength $passwords]} {
- error "Failed to log in!"
- }
- expect {
- "word:" {
- send [lindex $passwords $idx]\n
- }
- -exact in$ {
- break
- }
- }
- }
- puts "Logged in with [lindex $passwords $idx]"
- # login already expected a prompt
- send "set ethernetDoSThrottleShutoff 1 1 1\r"
- expect -exact in$
- send "get ethernetDoSThrottleShutoff\r"
- expect -exact in$
- send "exit\r"
- expect eof ;# this bit is important!