0

Currently, I am working on a script to automatize a process, in this point my script is short and simple but I have had some Issues with expect/send.

code:

#!/usr/bin/expect -f
#!/bin/bash

set ip ***
set ip2 ***
set user ***
set usr2 ***
set OTP [lindex $argv 0]
spawn ssh "usr@$ip";
expect "OTP Password:"
send -- "$OTP"
interact
expect "prompt >"
send -- "ssh usr2@$ip2"
interact

For this point script works until the first ssh but... for the second ssh (expect "prompt >" / send -- "ssh $ip2") It doesn't work... I don't get the idea why. I have tried with some commands like expect eof, wait, timeout and nothing as well I checked to expect version is on latest (5.45).

Do you have any idea? thanks!

dejanualex
  • 3,872
  • 6
  • 22
  • 37

1 Answers1

1

Your spawn looks fine to me, but in the send, you forgot to send the carriage return, which actually terminates the command:

send -- "$OTP\r"
user1934428
  • 19,864
  • 7
  • 42
  • 87