Link to home
Start Free TrialLog in
Avatar of amrox
amrox

asked on

stdin pipe to expect script

I want to feed a string to an expect script and have it stored in a variable and used as a password.
Needs to be invoked as:
echo "my_password" | ./myscript.exp

Anyone know how to do this?
Please see script example below:


#!/usr/bin/expect -f 
 
 
#### *** insert some command here to set $PASSWD to stdin ***
 
spawn ssh test@localhost
expect "*?password:*" { send "$PASSWD\n" }
expect "$ " 
send "exit\n"
interact

Open in new window

Avatar of kazimur
kazimur

You'd better run your script as ./myscript.exp "my password". Then you can create $PASSWD very simple: set PASSWD [lindex $argv 0]
Avatar of amrox

ASKER

yes, I know how to use arguments, but this is not what I want.

Is it possible to do what I've asked?
ASKER CERTIFIED SOLUTION
Avatar of amrox
amrox

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial