1
我想创建一个Ruby
脚本,该脚本打开一个SSH伪连接,并保持打开状态。使用子进程在Ruby中保持SSH伪连接打开
我也想在例如它的帮助下发送密码。 expect
。
我已经试过这样:(我已删除服务器名,密码和用户名)
#!/usr/bin/env ruby
require "pty"
require "expect"
username = 'USERNAME'
server = 'SERVERNAME'
password = 'PASSWORD'
r_f, w_f, pid = PTY.spawn("ssh -T -l #{username} #{server}")
w_f.sync = true
r_f.expect(/.*asswor.*/, 600) do |output|
w_f.puts password
puts "Sending password"
end
# If we are logged on, we get a message with "Hello, username"
r_f.expect(/.*ello.*/) do
puts "You are now logged on."
end
然而,这似乎已收到其连接
Doh!这真的很简单。 – 2011-06-13 12:03:29