3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

net-ssh-multi gemを使ってみる

Last updated at Posted at 2013-09-18
  • rubyからsshで複数サーバーに対して操作がしたかったのでnet-ssh-multi gem(1.2.0)を使ってみた

  • capistranoはコマンドラインツールとしては引数がわかりにくいけどnet-ssh-multi + trollopあたりだと気楽にコマンドラインツール作れるかな?

  • サンプルスクリプト

  • SOCKS5プロキシを利用する環境なので指定

  • concurrent_connectionsで最大コネクション数を指定

require 'net/ssh/multi'
require 'net/ssh/proxy/socks5'                                                  

socks5 = Net::SSH::Proxy::SOCKS5.new('host', 1080, :user => 'user', :password => 'password')

Net::SSH::Multi.start(concurrent_connections => 1) do |session|
  session.use "[ec2のPublicDNS1]", 
              "[ec2のPublicDNS2]",
              :user => 'ec2-user',
              :proxy => socks5,
              :keys => ["/private/key/path"]
  session.exec "echo hoge"
  session.loop
end
  • 実行結果
$ bundle exec ruby test.rb
[ec2のPublicDNS1] hoge
[ec2のPublicDNS2] hoge
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?