Skip to content

Instantly share code, notes, and snippets.

@charleskirk
Created October 26, 2012 19:07
Show Gist options
  • Save charleskirk/3960784 to your computer and use it in GitHub Desktop.
Save charleskirk/3960784 to your computer and use it in GitHub Desktop.
Net::SSH::Multi.start(:on_error => :ignore) do |ssh|
Instance.all.each do |instance|
if instance.status == 'running'
ssh.use 'portal_user@' + instance.ip_address, :keys => ['~/.ssh/portal_user.pem']
end
end
stdout = ""
# run this on all boxes
ssh.open_channel do |channel|
channel.request_pty do |c, success|
raise "Could not request pty" unless success
channel.exec "wget -q -O - http://169.254.169.254/latest/meta-data/instance-id; sudo /usr/sbin/httpd -t -D DUMP_VHOSTS 2>&1 | grep namevhost | awk '{print $2,$4,$5}'; cat /etc/*release*"
channel.on_data do |c_, data|
raise data.inspect
responses = data.gsub("\r", '').split("\n")
if responses.count > 1
if(response.count < 3)
raise response.inspect
end
instance_system = responses[-3] << responses[-2]
@ssh_instance = Instance.where(:dns_name => responses.last).first
if @ssh_instance
@ssh_instance.os_data = instance_system.to_s
@ssh_instance.save
responses[0...-4].each do |response|
record = response.split(' ')
@ssh_instance.vhosts.create(:name => record[1], :vhost => record[1], :port => record[0], :conf_location => record[2])
end
end
end
end
end
end
ssh.loop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment