Operating System - HP-UX
1832809 Members
2706 Online
110045 Solutions
New Discussion

Re: Comparing Software List

 
SOLVED
Go to solution
Mark Treen_1
Advisor

Comparing Software List

Guys

I have two servers and on both i have run swlist -l patch > /tmp/patches_servera.txt and then the same command but on server b.

What i want to know is the best way with these two text files, the command to know what patches exist in serverb BUT NOT in servera.

I guess it will be diff but no manipultion using the syntaxes gives me what I need!

Any ideas?

Cheers

Mark

Mark Treen
7 REPLIES 7
Mel Burslan
Honored Contributor
Solution

Re: Comparing Software List

I personally do not like the output diff command generates, hence I have this little script to determine what you are looking for

on server a
swlist -l product | grep PH | awk {'print $1'} > /tmp/patch_serverA

on server b
swlist -l product | grep PH | awk {'print $1'} > /tmp/patch_serverB

combine two files into the same place by ftp or your favorite way of file transfer.

then

for patch in `cat patch_serverB`
do
grep -q ${patch) patch_serverA; r=${?}
if [ $r -ne 0 ]
then
echo ${patch} >> /tmp/patches_not_on_serverA
fi
done

when this finishes running, you will have the output you wish in the file /tmp/patches_not_on_serverA

Hope this helps
________________________________
UNIX because I majored in cryptology...
Bharat Katkar
Honored Contributor

Re: Comparing Software List

Hi Mark,
One small script
Before executing the script make sure you create file file1 which contains patch information of serverB.
# swlist -l patch > file1
ftp file1 to serverA.
Execute following script on serverA

Script::

#!/usr/bin/ksh
list=`swlist -l patch | grep PH| awk '{ print $1 }' | grep -v "#"`
func1()
{
var1=$#
while true
do
if [ $var1 -gt 0 ]
then
result=`cat file1 | grep $1 | wc -l`
if [ $result -eq 0 ]
then
echo " Patch $1 does not exists "
fi
let var1=var1-1
shift 1
else
exit
fi
done

Script Ends::

Now this will tell you what patches those are present on Server are not on ServerB.

Do vice versa also i.e. create file1 for ServerA and execute the script on ServerB.

Picture should be quite clear.

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
Bharat Katkar
Honored Contributor

Re: Comparing Software List

Just forgot to add one line to the script.
Append the script at the end with:

func1 $list

regards,
You need to know a lot to actually know how little you know
Senthil Kumar .A_1
Honored Contributor

Re: Comparing Software List

Hi Mark,

Use "comm" command. Check its man pages for options.

Regards
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Senthil Kumar .A_1
Honored Contributor

Re: Comparing Software List

Hi mark,

for your present scenario...

Type these command sequence in your terminal..

sort /tmp/patches_servera.txt > /tmp/sorted_patches_servera.txt
sort /tmp/patches_serverb.txt > /tmp/sorted_patches_serverb.txt
echo "patches only found in SERVER - A"
comm -23 /tmp/sorted_patches_servera.txt /tmp/sorted_patches_serverb.txt
echo "patches only found in SERVER - B"
comm -13 /tmp/sorted_patches_servera.txt /tmp/sorted_patches_serverb.txt

Regards.

PS: if you want to know the common patches use
comm -12 /tmp/sorted_patches_servera.txt /tmp/sorted_patches_serverb.txt

and if you want all the details is single shot , then use comm file1 file2 ,this will give you three columned output.
1st column : entries unique to file1
2nd column : entries unique to file2
3rd column : entries common in file1 and file2.

Note: need to sort both the files before you feed it to "comm" command.

Cheers.
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Senthil Kumar .A_1
Honored Contributor

Re: Comparing Software List

Hi mark,

sorry to make my reply into three pieces...

i forgot about one other thing..

before proceeding with the steps put in my previous reply... please make sure the files are created using following command

in SERVER A
swlist -l product | grep PH | awk '{print $1}' > /tmp/patches_servera.txt

in SERVER B
swlist -l product | grep PH | awk '{print $1}' > /tmp/patches_serverb.txt

Sorry Mel Burslan : had to borrow one of your lines...

Regards.
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Mark Treen_1
Advisor

Re: Comparing Software List

Thanks for the advice
Mark Treen