Skip to content

Instantly share code, notes, and snippets.

@Narnach
Created January 26, 2009 06:58
Show Gist options
  • Select an option

  • Save Narnach/52730 to your computer and use it in GitHub Desktop.

Select an option

Save Narnach/52730 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/ssh/gateway'
s1 = {:host=>'foo', :user => 'foobar', :options => {:password => 'barfoo', :port => 2221}}
s2 = {:host=>'bar', :user => 'foobar', :options => {:password => 'barfoo', :port => 2222}}
s3 = {:host=>'baz', :user => 'foobar', :options => {:password => 'barfoo', :port => 2223}}
s4 = {:host=>'moo', :user => 'foobar', :options => {:password => 'barfoo', :port => 2224}}
gw = Net::SSH::Gateway.new(s[:host], s[:user], s[:options)
gw_port = gw.open(s2[:host], s2[:port])
gw2 = Net::SSH::Gateway.new(s2[:host], s2[:user], s[:options].merge({:port => gw_port}))
gw2_port = gw2.open(s3[:host], s3[:port])
gw3 = Net::SSH::Gateway.new(s3[:host], s3[:user], s[:options].merge({:port => gw2_port}))
gw3.ssh(s4[:host], s4[:user], , s[:options]) do |session|
session.exec!('uptime')
end
gw2.shutdown!
gw.shutdown!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment