I need to automate logging into a TELNET session using expect, but I need to take care of multiple passwords for the same username.
Here's the flow I need to create:
- Open TELNET session to an IP
- Send user-name
- Send password
- Wrong password? Send the same user-name again, then a different password
- Should have successfully logged-in at this point...
For what it's worth, here's what I've got so far:
#!/usr/bin/expect
spawn telnet 192.168.40.100
expect "login:"
send "spongebob
"
expect "password:"
send "squarepants
"
expect "login incorrect" {
expect "login:"
send "spongebob
"
expect "password:"
send "rhombuspants
"
}
expect "prompt>" {
send_user "success!
"
}
send "blah...blah...blah
"
Needless to say this doesn't work, and nor does it look very pretty. From my adventures with Google expect seems to be something of a dark-art. Thanks in advance to anyone for assistance in the matter!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…