0

I have the following script:

#!/usr/bin/expect

set timeout 20

set cmd [lrange $argv 1 end]
set password [lindex $argv 0]

eval spawn $cmd

while {1} {
  expect "id_rsa"
  send "$password\r";
}

interact

which intends to expect "id_rsa" and enter the password repeatedly while the spawned $cmd is open.

Now the script works but will always end with error

send: spawn id expx not open while executing ...

I want to write my code in a proper way such that the while loop is exited properly via check and not via error catching in expect so that the error will not show up.

Thanks in advance.

1
  • What should the condition for exiting the loop be? It looks like what you have there is an endless loop that just keeps entering the password, and if you do that until EOF, there's nothing to interact with.
    – ilkkachu
    Jun 2, 2022 at 8:52

1 Answer 1

2

Try changing

while {1} {
  expect "id_rsa"
  send "$password\r";
}

interact

to

expect {
  id_rsa {
    send "$password\r"
    exp_continue         ;# this is the "looping" part
  }
  eof
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .