Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: b5b072b883
Fetching contributors…

Cannot retrieve contributors at this time

executable file 46 lines (36 sloc) 0.941 kB
#!/usr/bin/env ruby
require 'optparse'
unless ARGV.size >= 2
puts "Usage: ndo [options] HOST_SET COMMAND"
puts
puts "You need to specify at least a host set and a command."
exit 1
end
host_set, *cmd_parts = ARGV
command = cmd_parts.join(' ')
hosts = if host_set == '-'
# stdin
STDIN.readlines.map { |l| l.chomp }
else
File.read(
File.join(ENV['HOME'], '.ndo', host_set)).
lines.map { |l| l.chomp.strip }
end
$:.unshift File.dirname(__FILE__) + "/../lib"
require 'ndo'
require 'text/highlight'
hl = Text::ANSIHighlighter.new
String.highlighter = hl
results = Ndo::MultiHost.new(hosts).run(command)
results.each do |host, result|
next unless result.success?
output = result.stdout.chomp
if output.index("\n")
# Multiline output
output.gsub!(/\n/, "\n ")
output = " "+output
printf "%s {\n%s}\n\n", host.bold, output
else
printf "%-20s %s\n", host.bold, output
end
end
Jump to Line
Something went wrong with that request. Please try again.