Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created March 23, 2015 21:42
Show Gist options
  • Save djanatyn/0e726c9c5e8fa202221a to your computer and use it in GitHub Desktop.
Save djanatyn/0e726c9c5e8fa202221a to your computer and use it in GitHub Desktop.
create ssh tunnels according to yaml so I can rsync, to aid with migration to AWS
#!/usr/bin/env ruby
require 'yaml'
abort "usage: #{$0} <yaml>" unless ARGV.length == 1
filename = ARGV[0]; abort "could not find file: #{filename}" unless File.exists? filename
begin
servers = YAML::load_file filename
rescue Exception => e
puts 'error loading yaml - are you using the right syntax?'
abort e
end
threads = []
servers.keys.each do |s|
# exit if there's no ssh command
command = servers[s]['ssh_command']
if servers[s]['ssh_command'].nil?
puts "no ssh_command found for #{s}, skipping."
break
end
# otherwise do the thing in a thread
puts "updating #{s}..."
thread = Thread.new {
output = %x{yes | #{command} >/dev/null 2>&1 && echo "#{s} updated successfully!" || echo "#{s} FAILED"}
puts output
}
threads.push thread
end
# wait for all threads to finish
threads.each {|t| t.join }
# exit nicely if we get here
puts "done!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment