LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2013, 04:14 PM   #1
homer_3
Member
 
Registered: May 2008
Posts: 89

Rep: Reputation: 15
expect hangs


I'm trying to automate doing a multiple hop ssh login with an expect script. It almost works. I have to go from machine 1, to machine 2, to machine 3, to machine 4. I make it all the way to machine 3 and then expect just hangs. It also appears to be hanging at 'expect "~]"' in the 2nd pass of my loop. [user@host ~] prints out, so I don't see why it's hanging there. Is there something I am doing wrong?

My script is below and the command that fails is
Code:
expect expect_login.exp X.X.X.X 3
Code:
#!/usr/bin/expect -f
set gwIP [lrange $argv 0 0]
set gwUser "foo"
set gwPass "foo"

set pcPass "foo"
array set pcIPs[list 0 "X.X.X.X" 1 "X.X.X.X" 2 "X.X.X.X"]
set pcUsr "foo"

set timeout -1
set tabIdx [lrange $argv 1 1]

#################################
#Log into 1st machine           #
#################################
spawn /usr/bin/ssh -X ${gwUser}@${gwIP}
expect "*?assword*"
send -- "$gwPass\r"
expect "~]"

sleep 1
##################################
#Log into PCs from 1st machine   #
##################################
for {set i 0} {$i < $tabIdx} {incr i 1} {
  sleep 1
  puts "Logging into $pcIPs($i)\n"
  send -- "/usr/bin/ssh -X ${pcUsr}@$pcIPs($i)\r"
  expect "*?assword*"
  send -- "$pcPass\r"
  expect "*~]"
  send -- "\r"
}

interact
 
Old 03-21-2013, 04:54 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,317

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
Hi

Not sure why it hangs, but it's a lot easier to use ssh's ProxyCommand. Here's a guide:

http://sshmenu.sourceforge.net/artic...-mulithop.html
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM
expect: line seems to match exactly, however expect thinks not deadeyes Linux - General 5 06-16-2010 07:05 PM
Calling expect scripts from other expect scripts sevapopov Linux - Software 3 04-03-2008 10:33 PM
TCL/expect - parent hangs when child dies Hewson Programming 1 03-27-2007 09:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration