Last active
August 29, 2015 14:01
-
-
Save koudelka/370ca415718dd8709a42 to your computer and use it in GitHub Desktop.
Quick n' dirty utility to compare sysctls between two machines.
This file contains hidden or 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 | |
# | |
# This utility compares `sysctl -a` on two given boxes | |
# | |
puts "Usage: #{$PROGRAM_NAME} hostname other_hostname" and exit unless ARGV.length == 2 | |
SYSCTLS = {} | |
def sysctls(hostname) | |
raw = `ssh #{hostname} 'sysctl -a'` | |
Hash.new.tap do |packages| | |
raw.split("\n").each do |line| | |
name, value = *line.split('=').collect(&:strip) | |
SYSCTLS[name] ||= [] | |
SYSCTLS[name] << [hostname, value] | |
end | |
end | |
end | |
ARGV.each do |hostname| | |
sysctls hostname | |
end | |
exclusives = {} | |
shared = {} | |
SYSCTLS.each do |name, record| | |
if record.length == 1 | |
hostname = record.first.first | |
exclusives[hostname] ||= [] | |
exclusives[hostname] << name | |
elsif record.length == 2 | |
first_host_sysctl_value = record.first.last | |
second_host_sysctl_value = record.last.last | |
if first_host_sysctl_value != second_host_sysctl_value | |
shared[name] = record | |
end | |
else | |
puts "MULTIPLE values for sysctl #{name}, you figure it out: #{record}" | |
end | |
end | |
exclusives.each do |hostname, sysctls| | |
sysctls.each do |sysctl| | |
puts "ONLY #{hostname} has sysctl #{sysctl}" | |
end | |
end | |
shared.each do |name, information| | |
first_host_info = information.first | |
second_host_info = information.last | |
first_host = first_host_info.first | |
second_host = second_host_info.first | |
first_host_sysctl_value = first_host_info.last | |
second_host_sysctl_value = second_host_info.last | |
if first_host_sysctl_value != second_host_sysctl_value | |
differences = {first_host => first_host_sysctl_value, second_host => second_host_sysctl_value } | |
puts "BOTH #{name} #{differences}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment