LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-12-2011, 01:27 PM   #1
gabes
LQ Newbie
 
Registered: Sep 2011
Location: San Diego
Posts: 2

Rep: Reputation: Disabled
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 >
 
Old 09-12-2011, 05:11 PM   #2
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,090

Rep: Reputation: 41
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.
 
Old 09-12-2011, 05:52 PM   #3
gabes
LQ Newbie
 
Registered: Sep 2011
Location: San Diego
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-15-2011, 12:07 PM   #4
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,090

Rep: Reputation: 41
Quote:
Originally Posted by gabes View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] spawn with Expect script najee1987 Linux - General 5 05-25-2011 01:53 AM
exp_i_parse_states: : file16 is not an expect channel - use spawn -open to convert pcs1976 Programming 0 03-15-2011 07:58 AM
send: spawn id exp1025 not open in tcl/expect bharatbsharma Programming 3 04-22-2010 02:04 AM
Expect interpreter, spawn and cat Ricio Programming 11 08-16-2008 05:55 PM
Unexpected curly braces in expect script spawn command & bash suid problem slinx Programming 1 05-02-2008 01:47 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration