Script to compare RPMs on two different CentOS servers

I wanted to make sure that the same RPMs were installed on several servers. I wasn’t worried about versions of RPMs because everything should be kept up to date via yum. So I sat down and wrote the script below. It has been on my ToDo list for quite a while!

RRPM=$(ssh $REMOTESERVER "rpm -qa --queryformat '%{NAME}\n'" )
LRPM=$(rpm -qa --queryformat '%{NAME}\n')

echo "*** Missing from $REMOTESERVER" ***
grep -vf <(echo "$RRPM"| sort) <(echo "$LRPM"|sort)
echo
echo "*** Missing from Local system ***"
grep -vf <(echo "$LRPM"| sort) <(echo "$RRPM"|sort)
echo

This script connects to a remote machine and compares RPMs installed there to the RPMs that are installed locally.

,

2 Responses to Script to compare RPMs on two different CentOS servers

  1. Michael July 18, 2012 at 3:01 pm #

    Thanks for the code, here is my modified version that does exact maching on the names, so for instance it can tell you that you are missing php, php-cli, php-common even if the server has php installed

    RRPM=$(ssh $REMOTESERVER "rpm -qa --queryformat '%{NAME}\n' | sort | uniq" )
    LRPM=$(rpm -qa --queryformat '%{NAME}\n' | sort | uniq)
    
    echo "*** Missing from $REMOTESERVER ***"
    grep -vEf <(for rpm in $RRPM; do echo "^$rpm\$"; done| sort) <(for rpm in $LRPM; do echo "$rpm"; done |sort)
    echo
    echo "*** Missing from Local system ***"
    grep -vEf <(for rpm in $LRPM; do echo "^$rpm\$"; done| sort) <(for rpm in $RRPM; do echo "$rpm"; done |sort)
    echo
    
  2. jbmurphy July 18, 2012 at 3:04 pm #

    Thanks for taking the time to update/comment! I haven’t looked at this code in a while, but I believe I might need it soon, and I will incorporate your changes
    Thanks.