«

»

Sep 26

Servers package difference => “dpkg-diff”

Problem

You have two linux servers A and B, you want to know what installed packages are not in both servers (A-B joined with B-A).

Solution

The following script (dpkg-diff.sh, tested on GNU/Linux Debian Lenny/Squeeze).

dpkg-query command and a ssh server must be installed on both servers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
###
# FILE: dpkg-diff.sh
# AUTHOR: Olaf Reitmaier <[email protected]>
# LICENSE: GNU/GPL v3 (Visit www.gnu.org for more info)
# USAGE: Servers package difference => "dpkg-diff"
# WARNING: Modify header vars according to your needs.
##
 
# Header variables
 
s1=server1.example.com
s2=server2.example.com
u1=testuser
u2=$u1
# Exclude lib* packages
ft="-v ^lib"
f1=/tmp/dpkg-diff.1
f2=/tmp/dpkg-diff.2
 
# Do not edit this lines unless you know what your doing!
 
ssh $u1@$s1 "dpkg-query --list" | grep '^ii' | awk '{print $2}' > $f1
ssh $u2@$s2 "dpkg-query --list" | grep '^ii' | awk '{print $2}' > $f2
 
clear
 
echo "Only in $s1"
 
cat $f1 | grep $ft | sort | while read package
do
	if [ $(cat $f2  | grep $package | wc -l) -eq 0 ]
	then
		echo -n "$package "
	fi
done
echo
echo
 
echo "Only in $s2"
 
cat $f2 | grep $ft | sort | while read package
do
	if [ $(cat $f1 | grep $package | wc -l) -eq 0 ]
	then
		echo -n "$package "
	fi
done
echo
echo

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

nine + four =