How to capture output from a remote command in Capistrano? How to capture output from a remote command in Capistrano? ruby ruby

How to capture output from a remote command in Capistrano?


Maybe capture?

"The capture helper will execute the given command on the first matching server, and will return the output of the command as a string."

https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Inspection-Capture


If you want to capture the output of multiple hosts, use run with a block: e.g.:

 desc "capture output from multiple servers"  task :capture_multiple_servers, :roles => [:some_servers] do    results = {}    run "hostname --fqdn" do |channel, stream, data|      if stream == :out        results[channel[:host]] = [] unless results.key?(channel[:host])        results[channel[:host]] << data if stream == :out      end    end    puts "Your results were:"    results.keys.sort.each do | host |      puts "#{host}:#{results[host].join}"    end  end