B.Mr.W.
B.Mr.W.

Reputation: 19648

Linux Expect SSH hangs

I tried to install R across a cluster of computers and someone told me to check out Expect.

I was following a tutorial about Linux Expect Command to automate the process of ssh into node and install open source R automatically.

I am kind of stuck on the ssh part: (Tutorial goes here)

#!/usr/bin/expect -f 

if {[llength $argv] != 3} {
puts "usage: ssh.exp username server password"
exit 1
}

set username [lrange $argv 0 0]
set server [lrange $argv 1 1]
set password [lrange $argv 2 2]

set timeout 60

spawn ssh $username@$server.mycompany.com

match_max 100000

expect "*?assword:*"

send -- "$password\r"

send -- "\r"

expect eof

I can run the code and log into the remote server, however, I type in ls and it just hangs on the remote server side. And I ctrl + c and it log out and goes back to my host server.

Can any one tell me how to continue the process in Expect after you log in.

Update: Due to Ireeder's answer.

You just need to replace expect eof with interact and it will hand over the control to the user.

Upvotes: 0

Views: 3653

Answers (1)

lreeder
lreeder

Reputation: 12224

Put interact at the end of the script, which returns control to the script caller, and allows you to interact with the remote shell. So change your script like this:

#... top of script
send -- "$password\r"

send -- "\r"

interact

See http://wiki.tcl.tk/3914

Upvotes: 2

Related Questions