开发者

How to use expect script in ruby on rails?

开发者 https://www.devze.com 2023-02-18 18:55 出处:网络
Can you please help me?. How can i use the expect script in ruby. spawn scp /tmp/*.txt remoteserver:/vg/

Can you please help me?. How can i use the expect script in ruby.

spawn scp /tmp/*.txt remoteserver:/vg/
expect "password"
send "MY PASSWORD"
interact

Because, i need to transfer the bulk files from one server to ano开发者_如何学Pythonther server through scp command. But, when i use the wildcard file transfer (/tmp/*.txt) it shows the following error

No such file or directory Killed by signal 1.

Then, i had changed my code like as follows. (Note: i have used the file name directly).

spawn scp /tmp/first.txt remoteserver:/vg/
expect "password"
send "MY PASSWORD"
interact

So , I have just jump into rails.

$files = Dir.glob("/tmp/*.txt")
for f in @files
[I need to use the expect script here]
expect {....#{f}...}
end

Thanks


You do want to use ssh keys for this. It's not hard to set up, then you don't have to worry about it.

You probably want your expect script to look like this:

set scp_command [linsert $argv0 scp]
lappend scp_command remote_server:/vg/
eval spawn $scp_command

expect password
send "MYPASSWORD\r"
expect eof

and the Ruby part would be something like

system "expect", "expect_script.exp", Dir.glob("/tmp/*.txt")


Glenn mentioned using ssh keys - they certainly make your life easier when you're working with Expect scripts.

A few year ago I wrote a blog post on how to use generate and use ssh keys with putty on Windows.

http://soniahamilton.wordpress.com/2008/09/05/how-to-use-putty-with-ssh-keys-on-windows/

0

精彩评论

暂无评论...
验证码 换一张
取 消