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

expect script failing ...almost works

Status
Not open for further replies.

dans45

Technical User
Feb 13, 2003
43
US
Hello,
I'm running this script on my linux machine.

#!/bin/bash
# \
exec expect -f "$0" ${1+"$@"}
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
send "$password\r"
expect "assword:"
send "$password\r"
expect eof
When I execute it on my linux machine:
setpw usera apassword
The Retry password request times out.
Can I get some help on this.
Thanks Much.
 
Hi, It is deliberate. Actually i copied this script exactly a shown from another website. I have not written any of my expect scripts before but I heard it was created just for this purpose i.e. to respond to operator prompts.
 
I use "assword" too as some OS's prompt for "Password" and others for "password".

Incidentally, if this is Linux some of the passwd binaries support the --stdin option, which precludes the need for expect, maybe you should try that first?

Failing that, can you post a copy of the screen output when you actually run the script?

Annihilannic.
 
I tried the passwd binary but it did not seem to work. Maybe I ran it incorrectly. I did get the expect script to work by adding some delay.
#!/bin/sh
# \
exec expect -f "$0" ${1+"$@"}
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
time {sleep 5}
send "$password\r"
expect "assword:"
time {sleep 5}
send "$password\r"
expect eof
Not sure why the time delay before the send was required but it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top