There are processes that take in a password partway through computation. I wish to insert a password at the start of the process, so I am trying to create a generic expect script that will spawn a process, then give it a password.
This expect script takes in the password to enter and the process to spawn:
#!/usr/bin/expect
set timeout 120
# Get program to spawn and password to send
set pswd [lindex $argv 0]
set program [lindex $argv 1]
spawn $program
expect "Password:"
send "$pswd\r"
interact
This will be called from a bash function:
function vup {
echo -n "Enter Password: "
read -s pswd
echo
expectPassword.exp $pswd "vagrant up"
}
But I get the error:
couldn't execute "vagrant up": no such file or directory
while executing
"spawn [join $program]"
This script seems to work when I use it on a program without arguments. But I'm not sure how to make it work for one with a variable number of arguments.
One way is to use eval
:
eval spawn $program
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With