1

I don't know what's wrong with the script. I set up a new profile on Iterm terminal to run the script, but it never works and closes immediately. Here's the script:

#!/usr/bin/expect -f

set timeout 120
set secret mysecret
set username asdf
set host {123.456.789.010}
set password password123
log_user 0

spawn oathtool --totp --base32 $secret
expect -re \\d+
sleep 400
set otp $expect_out(0,string)

spawn ssh -2 $username@$host
expect "*assword:*"
send "$password\n"
expect "Enter Google Authenticator code:"
send "$otp\n"
interact

1 Answers1

0

First, test you ssh connection with:

ssh -v <auser>@<apassword> 

That will validate the SSH session works.
Make sure to not use ssh -T ..., since you might need a terminal for expect commands to work.

Second, add at least an echo at the beginning of the script, to see if it is called:

puts "Script running\r"

Third, see if a bash script, with part of it using expect as in here, would work better in this case

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @glennjackman I meant using the expect command which is the equivalent of `echo`, since it is an expect script, not a bash script. So yes: puts. – VonC Apr 08 '20 at 18:57