Skip to content

Instantly share code, notes, and snippets.

@lusis
Created November 15, 2010 18:27
Show Gist options
  • Save lusis/700730 to your computer and use it in GitHub Desktop.
Save lusis/700730 to your computer and use it in GitHub Desktop.
quick and dirty ec2 auditing
require 'net/ssh/multi'
require 'fog'
require 'yaml'
require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: audit.rb [options]"
opts.on( '-c', '--command CMD', 'Command to execute') do |command|
options[:command] = command
end
end
optparse.parse!
settings = YAML.load_file('/home/jvincent/.fog')
@aws_access_key_id = settings[:default][:aws_access_key_id]
@aws_secret_access_key = settings[:default][:aws_secret_access_key]
connection = Fog::AWS::Compute.new(:aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key)
instances = connection.servers.all
Net::SSH::Multi.start do |session|
instances.each do |host|
session.use "root@#{host.dns_name}"
end
session.exec "#{options[:command]}"
session.loop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment