Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect and SSH help needed

Status
Not open for further replies.

pcorchary

MIS
Feb 23, 2002
60
US
I need to run remote apps via ssh. Easily done. However I'm trying to automate this, and despite 15+ years in unix, I've never used expect before :) (just sh/ksh and some perl)

#!/usr/bin/expect
#
# for now, assume called with [host] [user] [passwd]
spawn /usr/bin/ssh [lindex $argv 0] -l [lindex $argv 1]
expect {*password:}
send "[lindex $argv 2]\r"
#
send "<command>\r"
#
expect {*home*} exit

My problem is that the target systems might have either of two password. I need to write expect that will try the first passwd, and if denied, try the second, but so far I've been unsuccessful, and really been struggling with expect syntax (I know ... it's like tkl - sorry I've been avoiding that one too :)

Thanks in advance ... phil
 
Many ways to do it. One simple way below:

send "firstpassword\r"

while 1 {
expect {
"receive login successfully text" { do yo stuff; then quit }
"password incorrect text" { send "second password\r" }
}
}

dreamer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top