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