Skip to content

Instantly share code, notes, and snippets.

@sirhopcount
Forked from davidkrider/find_uncommitted.rb
Created November 26, 2012 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirhopcount/4148229 to your computer and use it in GitHub Desktop.
Save sirhopcount/4148229 to your computer and use it in GitHub Desktop.
Rancid script to find uncommitted changes which would be lost on a reboot
#!/usr/bin/ruby
File.open("all/router.db").each do |line|
(device, type, state) = line.split(":")
if state == "up\n"
if type == "vyatta"
command = "~/bin/clogin"
written = `#{command} -c 'cat /opt/vyatta/etc/config/config.boot' #{device} > #{dev`
running = `#{command} -c 'show configuration' #{device} > #{device}.running`
else
if type == "hp"
command = "~/bin/hlogin"
elsif type == "cisco"
command = "~/bin/clogin"
end
written = `#{command} -c 'show config' #{device} > #{device}.written`
running = `#{command} -c 'show run' #{device} > #{device}.running`
end
diff = `diff #{device}.written #{device}.running`
counts = `diff #{device}.written #{device}.running | wc`
(lines, words, chars, file) = counts.split
if (type == "hp" && lines.to_i > 8) ||
(type == "cisco" && lines.to_i > 12)
puts "There are uncommitted changes pending in #{device}!"
puts diff
end
File.delete("#{device}.written")
File.delete("#{device}.running")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment