LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Expect: spawn id expr4 not open (https://www.linuxquestions.org/questions/linux-general-1/expect-spawn-id-expr4-not-open-902634/)

gabes 09-12-2011 02:27 PM

Expect: spawn id expr4 not open
 
Hello,

I've seen a few posts with this same error, but so far none of them have seemed to be quite the same issue.

I am writing an expect script to automatically set up ssh keys between two systems. Right now it's working for all cases except when the host key for a system changes and the verification fails, causing the spawned ssh to instantly return, causing the next send to yield this error:
expect: spawn id exp4 not open

Any ideas how to fix this?

while { 1 > 0 } {
send_user "Connecting to $server\n"
spawn ssh $server
expect {

"$server:~ # " { atSystem }

"(yes/no)? " {
send "yes\n"
expect {

"$server:~ # " { atSystem }

"Password: " { needPassword $password $sshkey }

}
}

"Password: " { needPassword $password $sshkey }

default {
expectPrompt
spawn sed -i '/$server/d' /root/.ssh/known_hosts
}

}
}


The default case is the one that is causing the issue. It's occurring in expectPrompt, which just has blank expect cases for #,$, and >

trey85stang 09-12-2011 06:11 PM

Thought about just using the stricthostkeychecking=no option in the ssh client?

ssh -o StrictHostKeyChecking=no

you're probably in the same boat I am and have servers reimaged all the time not preserving the the hostkeys.

gabes 09-12-2011 06:52 PM

Thanks for the response! That is the exact boat I'm in, but I actually fixed the issue just before seeing your post. Rather than expecting a prompt, I used exec to run the sed command in the background, deleting the problematic lines in the known_hosts file. The script then reentered that infinite loop, only this time the newly spawned ssh didn't complain and it could proceed accordingly.

trey85stang 09-15-2011 01:07 PM

Quote:

Originally Posted by gabes (Post 4470084)
Thanks for the response! That is the exact boat I'm in, but I actually fixed the issue just before seeing your post. Rather than expecting a prompt, I used exec to run the sed command in the background, deleting the problematic lines in the known_hosts file. The script then reentered that infinite loop, only this time the newly spawned ssh didn't complain and it could proceed accordingly.

glad you got it fixed, if you were to choose to use stricthostkeychecking=no you would not even have to worry about respinding with yes. and you would be able to ditch that section in the script.


All times are GMT -5. The time now is 12:53 AM.