0

When I run echo "passphrase" | expect expect.exp "hostname", everything works fine, but expect exits immediately.

expect.exp

#!/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
sunknudsen
  • 6,356
  • 3
  • 39
  • 76
  • Show output of `admin@$hostname`. – Cyrus Sep 08 '19 at 15:13
  • take a look at [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect) which you can use to write *Expect* scripts with **shell code only**. – pynexj Sep 09 '19 at 13:58

2 Answers2

2

interact does not work when stdin is not a tty. You can pass the password as a command line option, just like the hostname.

pynexj
  • 19,215
  • 5
  • 38
  • 56
1

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"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352