Featured post
unix - expect script freezes when called from Ruby -
i've list of hosts on need install public key. purpose, i've written ruby script calls expect script , passes password, host name , public key file. expect script in turn performs ssh-copy-id each host, feeding in password , answering "yes" unknown host keys.
the expect script works absolutely fine when run command line. when executed ruby script, expect fails answer "yes" unknown host key confirmation : "are sure want continue connecting (yes/no)?". expect script freezes when yes/no question thrown it.
any appreciated.
here ruby script :
#!/usr/bin/env ruby -w hosts=['test@blah1.edu','test2@blah2.edu','test3@blah3.edu'] password="blahblahblah" key_file="/home/blah/.ssh/id_rsa.pub" hosts.each{ |host| command="expect sshcopy.exp #{host} #{key_file} #{password}" `#{command}` }
and here expect script sshcopy.exp :
set host [lrange $argv 0 0] set key_file [lrange $argv 1 1] set password [lrange $argv 2 2] spawn ssh-copy-id -i $key_file $host expect -nocase "*password: $" {send "$password\r"; interact} -nocase "*are sure want continue connecting (yes/no)? $" {send "yes\r"} eof{exit} expect -nocase "*password: $" {send "$password\r"; interact} eof{exit}
you see 2 expect statements above. first statement handles case when password asked (i.e. host key known) interacting immediately. handles case when unknown host identified, answering "yes".
the second expect statement executed when first expect answered "yes" leading password being asked.
i imagine problem call expect script `backticks`
expect script interacts. seems ruby backticks don't allow full interaction (blocking stdin perhaps). might want investigate ruby's expect module , away separate expect script.
- Get link
- X
- Other Apps
Comments
Post a Comment