Last active
January 16, 2018 16:17
-
-
Save dgulino/b65e8be133ba9466793d to your computer and use it in GitHub Desktop.
Graphic diff of file across multiple remote machines via SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
#osx: brew install diffuse | |
#linux rpm: rpm install diffuse | |
require 'optparse' | |
require 'pp' | |
options = {} | |
OptionParser.new do |parser| | |
parser.define_head "Distributed Diff" | |
parser.on('-h', '--hosts HOSTS') do |v| | |
options[:hosts] = v | |
end | |
parser.on('-f', '--file FILE') do |v| | |
options[:file] = v | |
end | |
end.parse! | |
unless options.include?(:hosts) | |
puts("You need to specify hosts with --hosts") | |
exit! 1 | |
end | |
unless options.include?(:file) | |
puts("You need to specify a file path with --file") | |
exit! 1 | |
end | |
hosts = options[:hosts] | |
file = options[:file] | |
host_list = hosts.split(",") | |
def create_ssh_command(host,file) | |
#if osx, need to use the brew version of ssh /usr/local/bin/ssh | |
return "<(ssh -ttt -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5 #{host} sudo cat #{file})" | |
end | |
def create_diff_command(diff_cmd,host_list,file) | |
host_list.each do |host| | |
diff_cmd += " " + create_ssh_command(host,file) | |
end | |
return diff_cmd | |
end | |
diff_cmd = create_diff_command("/bin/bash -c 'diffuse",host_list, file) + "'" | |
exec diff_cmd | |
#diffuse messes up terminal. run 'reset' to fix after running this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment