When I run echo "passphrase" | expect expect.exp "hostname"
echo "passphrase" | expect expect.exp "hostname"
, everything works fine, but expect
exits immediately.
#!/usr/bin/expect
set passphrase [gets stdin]
set hostname [lindex $argv 0]
spawn ssh admin@$hostname
expect "passphrase"
send "$passphrase\r"
expect "admin@$hostname"
send "clear\r"
interact
interact
does not work when stdin is not a tty. You can pass the password as a command line option, just like the hostname.
You might want to use the environment to pass the passphrase:
# shell code
export passphrase="pass phrase"
expect expect.exp hostname
# expect code
...
send "$env(passphrase)\r"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.