Linux: Comparing packages on two servers and installing the difference.

I know this isn’t Oracle related but if you have a position in a small company like myself, chances are you are performing more than DBA duties.   We just recently hired a linux admin but he’s on vacation this week and there’s a new server to stage for a Portal environment.

In the past I have just run system-install-packages on an existing server and the new one and compare the packages.   Time consuming, error prone, etc.  Also, any patches not installed from the base system packages won’t be captured.

Given those reasons I decided to use the command line.   If you have done something similar in the past and have a better way of doing it feel free to leave a comment.

Step 1:  Get a list of RPM packages from both servers:

rpm -qa --qf "%{NAME}\n” | sort > rpms_newserver.txt

Do the same on the second server.    Since the packages may not have been installed in the same order, I pipe it to sort, otherwise I believe it would cause problems with the next step.

The rpms_newserver.txt document will have a listing of files, ex:



Step 2: Put both package lists in the same directory on the new server and run the linux command diff to compare the files.

diff rpms_oldserver.txt rpms_newserver.txt | grep "<" > package_list.txt

The diff command compares two files and displays the differences.   To get a list of the lines missing from the rpms_newserver.txt file we grep for the less than arrow “<” and pipe it to a new file. 

Step 3: The package_list.txt document is in the same format as the files in step 1.   Next I used vi to insert the yum command into the file so it can be executed like a script.

Open the package_list.txt file with vi and type:

:1,$s/< /yum install -y /g

Save the document and now it looks like:

yum install -y a2ps
yum install -y alacarte
yum install -y alchemist

Step 4:

Execute the package_list.txt document:

sh package_list.txt

That’s it, once it finishes all the packages should be installed.