Skip to content

Instantly share code, notes, and snippets.

@gipi
Created May 24, 2013 19:48
Show Gist options
  • Save gipi/5646046 to your computer and use it in GitHub Desktop.
Save gipi/5646046 to your computer and use it in GitHub Desktop.
dpkg -l between servers and compare them (work in progress)
#!/usr/bin/env python
pkg_a = {}
pkg_b = {}
def create_pkg_list(a):
pkg = {}
with open(a) as f:
for line in f.readlines():
component = filter(lambda x: x != '', line.split(' '))
pkg[component[1]] = component[2]
return pkg
if __name__ == '__main__':
import sys
if len(sys.argv) < 3:
print >> sys.stderr, 'usage: %s <file1> <file2>' % sys.argv[0]
sys.exit(0)
pkg_a = create_pkg_list(sys.argv[1])
pkg_b = create_pkg_list(sys.argv[2])
for key in pkg_a.keys():
pkg_b_value = pkg_b.get(key, None)
if pkg_b_value and pkg_b_value != pkg_a[key]:
print "%s\t\t\t\t\t%s\t%s" % (
key[:16],
pkg_a[key],
pkg_b_value
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment