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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Expect forum --- so maybe someone knows the answer

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
Need to run something remotely and am using
Expect which works. However, there are times
when I'm prompted differently and I'm unsure
how to get around it.

For example:
at times prompted:
(yes/no)?
Password:

other times prompted:
Password:

To account for this I've used:
Code:
expect {
	"(yes/no)?" { send "yes\r" }
	"Password:" { send "mypassword\r" }
}
set timeout -1

This works fine, except after the first password
is entered the program runs and after a few
minutes there is a second password prompt.
Adding another expect "Password:" { send "mypwd\r" }
doesn't work.

For example:
Code:
expect {
	"(yes/no)?" { send "yes\r" }
	"Password:" { send "mypassword\r" }
}
set timeout -1
expect "Password:" { send "mypassword\r" }
set timeout -1

This doesn't work and it sits waiting for the
password to be entered.

If it doesn't prompt for yes/no then this works:
Code:
expect "Password:" { send "mypassword\r" }
set timeout -1
expect "Password:" { send "mypassword\r" }
set timeout -1

How do I answer the second password prompt if
there is an initial yes/no?

Thanks!
 
Expect is an extension of the Tcl language, so if the below doesn't help you may have more luck in the Tcl/Tk forum.

I used something like this:

Code:
expect {
    "(yes/no)?" { send "yes\r"; exp_continue }
    "Password:" { send "mypassword\r" }
}
set timeout -1
expect "Password:" { send "mypassword\r" }
set timeout -1

The exp_continue makes it repeat the search for strings matching that first expect clause (otherwise it exits that clause), if I recall correctly.

Annihilannic.
 
Not the best practise I know, but I usually send a "yes" regardless, as on most *nix type platroms a "password" request comes in three times. Based on benchmarking - didn't really have any impact on the execution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top