Created
June 30, 2011 13:29
-
-
Save davidkrider/1056236 to your computer and use it in GitHub Desktop.
Rancid script to find uncommitted changes which would be lost on a reboot
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/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
written = `#{command} -c 'cat /opt/vyatta/etc/config/config.boot' #{device} > #{dev
Missing a closing } at the end of the line.