1

Net::SSH::Multi ライブラリを動作させるのに問題があります。各ボックスに接続してそのコマンドを実行する必要があります。出力を取得しようとしています。

これが私のコードです:

#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/ssh/multi'

@ssh_responses = Array.new
puts "Starting vhost grab..."
# SSH into each instance, and download Vhost Dump
Net::SSH::Multi.start(:on_error => :ignore) do |ssh|

  ssh.use 'ec2-1-1-1-1.compute-1.amazonaws.com', :user => 'portal_user', :keys => ['~/.ssh/portal_user.pem']
  ssh.use 'ec2-1-1-1-2.compute-1.amazonaws.com', :user => 'portal_user', :keys => ['~/.ssh/portal_user.pem']
  puts "Added servers..."
  stdout = ""
  # run this on all boxes
  ssh.exec 'pwd' do |channel, stream, data|
    puts "Trying execution..."
    channel.request_pty do |c, success|
      puts "Trying to request tty..."
      if success
        puts "Successfully requested tty"
        command = "sudo ls /root"
        c.exec(command) do |c, success, data|
          puts "Executing commands..."
          stdout << data if stream == :stdout
        end
        @ssh_responses << stdout
        puts "Storing responses..."
      end
    end
  end

  ssh.loop

end

puts @ssh_responses
puts "Script executed."

そして、実行から得られる応答は次のとおりです。

$ ruby serverAction.rb 
Starting vhost grab...
Added servers...
Trying execution...
Script executed.
4

0 に答える 0