7

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??

Eedoh
  • 5,818
  • 9
  • 38
  • 62
  • 1
    You're passing the remote command as an argument to ssh, so that ssh session will end when the remote command completes. There will be nothing to interact with. – glenn jackman Sep 20 '11 at 19:43
  • Yes, but that remote command should not end before it gets an input on "Continue to run (y/n)". After passing "y\r" it should run for about another 2 minutes... Shouldn't interact command forward the remote command's output to my stdout until the end of execution? – Eedoh Sep 20 '11 at 19:51
  • Are you *sure* you're getting to the [interact] in good shape, and not just timing-out? Do you know how to debug Expect dialogues? – Cameron Laird Sep 20 '11 at 23:48
  • I don't think I'm timing out, as timeout is set to 10 seconds, and I get the error message almost insantly. No, I don't know how to debug it (at least I'm not aware of any "official" tool, or method for doing so) :( – Eedoh Sep 21 '11 at 12:14
  • 1
    1. Start with http://wiki.tcl.tk/3173; 2. be sure you've resolved Glenn's observation. More details, later in the day. – Cameron Laird Sep 21 '11 at 12:59
  • 3
    exp_internal 1 ;# you'll be able to see what is coming from the spawned process. Also having log_user 0 while trying to debug is... counterproductive. – Duane Sep 29 '11 at 12:10
  • Cameron Laird thank you a lot... I managed to resolve my issues after reading this article you gave us link to. Also thx to Duane for pointing out the fact that log_user 0 is not helpful when debugging :D. Vote up for both of you. – Eedoh Sep 30 '11 at 09:41
  • I ran into this error when I was trying to use `plink` with a USB device. It turns out that my account did not have appropriate permissions to access USB devices, so the process was never spawned and the expect failed automagically. After setting the appropriate permissions everything worked as expected. – sherrellbc Jul 13 '16 at 12:58

5 Answers5

5

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.

sankar guda
  • 59
  • 1
  • 2
0

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.

0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
0

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

Bugs
  • 4,491
  • 9
  • 32
  • 41
lina
  • 1
0
/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 eof

EOF

-2

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.

kuroikenshi
  • 101
  • 10
  • For future readers that might see this answer: please do not delete `~/.ssh/config`, it will not magically fix the error. – Z4-tier Aug 19 '21 at 01:06