Eedoh
Eedoh

Reputation: 6268

spawn_id: spawn id exp6 not open

I know that this issue is already mentioned here, but the solution does not work for me.

I have this script (let's name it myscript.sh) that spawns a process on remote environment and that should interact with it.

#!/usr/bin/expect
log_user 0
set timeout 10
spawn ssh -o PubkeyAuthentication=no [lindex $argv 0] -n [lindex $argv 1]
expect "password:" {send "mypassword\r"}
expect "Continue to run (y/n)" {send "n\r"}
interact

When I call this script on local environment...

myscript.sh user@host "command1;./command2 parameter1 parameter2"

I get the above error at line 7 (interact)

Any ideas??

Upvotes: 7

Views: 40934

Answers (5)

竹蜻蜓vYv
竹蜻蜓vYv

Reputation: 11

You can use this script to handle different expectations, whether there was a "yes/no" or "password" or eof in case of no match.

/usr/bin/expect <<EOF
spawn ssh-copy-id -i $dest_user@$ip
expect {
  "yes/no" { 
    send "yes\r";exp_continue 
  } "password" { 
    send "$passwd\r" 
  } eof { 
    exit
  }
}
expect of

EOF

Upvotes: 1

kuroikenshi
kuroikenshi

Reputation: 101

I ran into this issue as well but it was due to me creating/editing the following file for an unrelated item:

~/.ssh/config

Once I deleted that, all my scripts began working and I no longer got that issue with my expect file.

Upvotes: -2

lina
lina

Reputation: 1

I had this problem and it was down to using the wrong port.

Upvotes: 0

sankar guda
sankar guda

Reputation: 69

I suspect the expect is not able to find out(matching) the pattern you are sending.

expect "password:" {send "mypassword\r"}
expect "Continue to run (y/n)" {send "n\r"}

Check out again whether the "password:" and "Continue to run (y/n)" are in correct CAPS.

If still getting the same error, you can try using regular expression.

Upvotes: 6

0x4a6f4672
0x4a6f4672

Reputation: 28245

Try to do a normal ssh without script. See if it works. Sometimes the remote host identification changes, and the host has a new ip or new key. Then it helps to remove the old key with ssh-keygen -f ~/.ssh/known_hosts -R old_host, or something similar.

Upvotes: 0

Related Questions