ssh 代理脚本在 ruby 中运行但不在 jruby 中运行

ssh proxy script runs in ruby but not in jruby

我有一个使用 net::ssh gem 的 ruby 脚本。

这是一个简单的脚本,用于通过跳转服务器到目标框。该框仅对跳出服务器可见。这是脚本:

require 'net/ssh/proxy/command'
require "net/ssh"

class TestTunnel
  def initialize
    proxy = Net::SSH::Proxy::Command.new('ssh admin@10.10.10.10 nc %h %p 2>/dev/null')
    p "proxy gotten"
    Net::SSH.start("host1", "admin", :password => "admin", :proxy => proxy) do |ssh|
      hostname = ssh.exec!("hostname")
      p "In #{hostname}"
    end
  end
end
b=TestTunnel.new

问题出在 ruby 中的脚本 运行s 而不是 jruby 中。我的框架 运行 关闭了 jruby,所以我需要将它与 jruby 一起使用。

我的解决方案是从我的 jruby 脚本中调用一个 bash 脚本来设置隧道和那里的 运行 命令,但我宁愿在 j[=38 中完成所有事情=].

这是我得到的错误:

~/src/main/ruby$ jruby --1.9 scripts/test_tunnel.rb 
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable - errno backtraces disabled; run with -Xerrno.backtrace=true to enable

当我 运行 在 ruby:

~/src/main/ruby$ ruby scripts/test_tunnel.rb 
"proxy gotten"
"In vz-int-api02\n"
~/src/main/ruby$ 

当我 运行 和 -Xerrno.backtrace=true 我可以看到 jruby 是 1.7.9 我可以看到它使用 ruby 1.9:

~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 scripts/test_tunnel.rb
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable - 
  read_nonblock at org/jruby/RubyIO.java:2856
           recv at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/proxy/command.rb:75
           fill at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/buffered_io.rb:65
    next_packet at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:88
   poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:183
           loop at org/jruby/RubyKernel.java:1519
   poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178
           wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:215
           loop at org/jruby/RubyKernel.java:1519
           wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:213
     initialize at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:87
          start at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh.rb:207
     initialize at scripts/test_tunnel.rb:8
     (root) at scripts/test_tunnel.rb:15
~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 --version
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_72-b15 +indy [linux-amd64]
~/src/main/ruby$

有什么方法可以像在 ruby 中那样在 jruby 中将其发送到 运行 还是我的解决方案是从 j 中调用 bash 脚本ruby 这样做的唯一方法是什么?

一个

这听起来很像 net-ssh 中的 this bug,已在 net-ssh 3.0.2 中修复。

关闭该问题 t 的提交消息是 "Bugfix: proxy command was using nonblocking io api incorrectly causing rare IO::EAGAIN errors",这听起来正是您所得到的。