简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM