Skip to content

Instantly share code, notes, and snippets.

@jonjensen
Created September 27, 2013 10:29
Show Gist options
  • Save jonjensen/6726674 to your computer and use it in GitHub Desktop.
Save jonjensen/6726674 to your computer and use it in GitHub Desktop.
Script to compare installed RPMs between two servers using ssh and the rpm command.
#!/bin/sh
test -n "$TMPDIR" || TMPDIR=/tmp
tmpfilebase="$TMPDIR/rpmdb-compare.$$"
if test $# -ne 2
then
echo "Usage: $0 [user@]server1 [user@]server2" >&2
echo "Special name localhost means this server, without ssh" >&2
exit 1
fi
for i in "$@"
do
tmpfile="$tmpfilebase.$i"
if test $i = localhost
then
rpm -qa --qf '%{NAME}.%{ARCH}\n' | sort > $tmpfile
else
ssh $i "rpm -qa --qf '%{NAME}.%{ARCH}\n'" | sort > $tmpfile
fi
done
echo "RPMs in $1 only:"
comm -23 "$tmpfilebase.$1" "$tmpfilebase.$2"
echo
echo "RPMs in $2 only:"
comm -13 "$tmpfilebase.$1" "$tmpfilebase.$2"
rm -f "$tmpfilebase.$1" "$tmpfilebase.$2"
@nomankhn1
Copy link

Its better if you mention how to use.

@chanslor
Copy link

chanslor commented Jul 7, 2017

Thanks for writing this script!
Simple and easy to use for comparing the differences of rpm installed on two systems.

@pakair
Copy link

pakair commented Aug 27, 2018

@nomankhn1 save the script as rpmdb, make it executable, then ./rpmdb user@servA user@servB
It will prompt for user@servA pw and user@servB pw, then it will list packages in servA and packages in servB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment