Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created March 10, 2011 22:59
Show Gist options
  • Save Burgestrand/865129 to your computer and use it in GitHub Desktop.
Save Burgestrand/865129 to your computer and use it in GitHub Desktop.
superman 127.0.0.1 Kim whoami
database 127.0.0.1 Kim sleep 1 && echo "Database says Hello!"
localhost 127.0.0.1 Kim date
[superman]
Kim
[database]
Database says Hello!
[localhost]
Thu Mar 10 23:56:15 CET 2011
require 'net/ssh'
ips = $stdin.readlines.map do |line|
label, host, user, command = line.split(' ', 4)
[label, Thread.new do
output = nil
Net::SSH.start(host, user) { |ssh| output = ssh.exec!(command) }
output.to_s
end, line]
end
ips.each do |(label, thread, _)|
puts "[#{label}]"
thread.value.each_line.map do |line|
puts " " + line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment