如何在 ruby on Rails 中使用 Expect 脚本?
你能帮我吗?我怎样才能在ruby中使用expect脚本?
spawn scp /tmp/*.txt remoteserver:/vg/
expect "password"
send "MY PASSWORD"
interact
因为,我需要通过 scp 命令将批量文件从一台服务器传输到另一台服务器。但是,当我使用通配符文件传输(/tmp/*.txt)时,它显示以下错误
没有这样的文件或目录 被信号 1 杀死。
然后,我更改了代码,如下所示。 (注:我直接使用文件名)。
spawn scp /tmp/first.txt remoteserver:/vg/
expect "password"
send "MY PASSWORD"
interact
所以,我刚刚跳入了 Rails。 <代码>
$files = Dir.glob("/tmp/*.txt")
for f in @files
[I need to use the expect script here]
expect {....#{f}...}
end
<代码> 谢谢
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 another 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确实想为此使用 ssh 密钥。设置起来并不难,所以你不用担心。
您可能希望您的期望脚本如下所示:
Ruby 部分类似于
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:
and the Ruby part would be something like
Glenn 提到使用 ssh 密钥 - 当您使用 Expect 脚本时,它们肯定会让您的生活更轻松。
几年前,我写了一篇关于如何在 Windows 上通过 putty 生成和使用 ssh 密钥的博客文章。
http:// soniahamilton.wordpress.com/2008/09/05/how-to-use-putty-with-ssh-keys-on-windows/
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/