User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,423 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,608 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1713 | Replies: 5
Reply
Join Date: Feb 2007
Posts: 2
Reputation: ripper is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ripper ripper is offline Offline
Newbie Poster

comparing versions

  #1  
Feb 9th, 2007
i need to find if the system has the latest version of a particular package and install if it dosent. how do i compare the versions?
assume that i use rpm to find the installed version and a separate file has info of the required(latest) version.
how do i do it ?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Posts: 29
Reputation: Joshua Gourgues is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Joshua Gourgues Joshua Gourgues is offline Offline
Light Poster

Re: comparing versions

  #2  
Feb 9th, 2007
What program are you tryin to update the revision for?
Reply With Quote  
Join Date: Feb 2007
Posts: 2
Reputation: ripper is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ripper ripper is offline Offline
Newbie Poster

Re: comparing versions

  #3  
Feb 14th, 2007
Originally Posted by Joshua Gourgues View Post
What program are you tryin to update the revision for?
php,mysql and apache
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: comparing versions

  #4  
Feb 14th, 2007
It depends, on Linux play around for a while with rpm -qa, on Solaris play around with pkginfo, on AIX, HP, and SCO (as well as the FreeBSD/NetBSD deriviates) I can't really help you. I don't remember there software management commands.

But as you can see, it depends on your operating system. It also depends on whether the packaging system was used at all, or if someone downloaded the source and compiled it, or maybe just a tar file version of a binary program.
Last edited by masijade : Feb 14th, 2007 at 2:42 am. Reason: added bsd types
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: May 2004
Posts: 10
Reputation: ajcamp is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
ajcamp ajcamp is offline Offline
Newbie Poster

Solution Re: comparing versions

  #5  
Apr 5th, 2007
Hi,
This may be your lucky day. I searched all over the internet and couldn't find an RPM compare program - you'd think there would be hundreds of them....So I wrote my own. Not elegant, but very functional. The key to getting useful information from rpm is using query formats --qf

The guts of this script is

# rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})

This script is probably real close to what you're wanting to do. It compares the installed RPMS against a -r requirements file. This script can show you how to parse off the version number from a RPM
so you can compare it against your requirements file.

# <this script> -c <fn> will generate a list of RPMS installed
# <this script> -r <fn> will compare against a requirements file

== snip =========================================
#!/bin/bash
# Andrew Campagnola
# This script will compare installed RPMs against a list of required RPMS
# It will also compare and list the versions of the RPMs
# ===============================================
# Options
# -a Report ALL RPMs - found, missing or mismatched versions
# -v Report missing and mismatched versions
# -m Only report missing RPMS
# -c Create a local RPM list file

usage="USAGE: rpmcompare [camvVh?:ri] \n-a(ALL) -m(MISSING) -v(MISMATCHED VERSION) -r <required rpms file> -i <installed RPMs file> -c <create local list> -V Verbose"

let verbose=0
let pause_mode=1

while getopts "Vh?i:r:c:avmp" options
do
case $options in
a ) report="all"
;;
c ) report="make_local_list"
catalog_file=$OPTARG
;;
v ) report="version"
;;
m ) report="missing"
;;
V ) let verbose=1
;;
p ) let pause_mode=1
;;
r ) required_file=$OPTARG
;;
i ) installed_file=$OPTARG
;;
h ) echo -e $usage
exit 1
;;
? ) echo -e $usage
exit 1
;;
* ) echo -e $usage
exit 1
;;
esac
done

if [ ! -n "$1" ]
then
echo -e $usage
exit 1
fi

echo -e "------------------------------\nReport Type = $report \nVerbose=$verbose \nReq's File: $required_file \nInstalled File: $installed_file\nPause Mode: $pause_mode\n------------------------------"
#
# -c Make a Local RPM Listing File (./local_installed_rpms)
#

if [ "$report" = "make_local_list" ] ; then

## rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE}(%{ARCH})(%{GROUP})\n' $var
rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})\n' > temp1
cat temp1 | tr ' ' '\n'| sort > temp2
cp temp2 $catalog_file
rm -f temp1 temp2
echo -e "Completed writing RPM catalog $catalog_file"
exit 0

fi
#
# Get required rpms list file (Remote Computer)
#
until test -f "$required_file"
do
echo "Can't find required file ("$required_file") - I need a file with the list of required RPMS: "
read required_file
done
#
# Got name of req file, now load it
#
echo "Reading Remote RPMS List from: < $required_file >"
remote_rpms=`cat $required_file | sort`
#
# Check for -i (Local Computer) List Of Installed RPMS
# If not supplied, a list will be generated using `rpm -qa`
#
if [ -s "$installed_file" ]
then
installed_rpms=`cat $installed_file`
echo -e "Reading Local Installed RPMS List from: < $installed_file >"
else
echo "No local catalog file specified: Querying (Local) installed RPMS"
## ? installed_rpms=`rpm -q --qf "\%{NAME}-\%{VERSION}-\%{RELEASE}(\%{ARCH})\n"`

rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})\n' > temp1
cat temp1 | tr ' ' '\n'| sort > temp2
installed_rpms=`cat temp2`
rm -f temp1 temp2
fi

echo "================================================================"

for check in $remote_rpms
do
let rpm_base_match=0

# c_base=${check%%-[0-9]*} # don't trim nums they can be part of name
c_base=${check%%&*}
# Trim Off Archecture from right of version
# c_arch="(${check##*(}"
c_arch=${check##*&}
c_version=${check%%&*}
#
# Trim base name from left of version
c_version=${c_version#*&}

if [ "$verbose" = "1" ] ; then echo -e "Checking For Required RPM: \nName: $c_base \nArch: $c_arch\nVer: $c_version" ; fi
#
# Check installed local RPMS for a match to $c_base
#
for installed in $installed_rpms
do

let rpm_base_match=0
i_base=${installed%%&*}
#
# Trim Off Archecture from right of version to (
#
i_arch=${installed##*&}
i_version=${installed%%&*}
#
# Trim base name from left of version
i_version=${i_version#*&}

# echo -e "Raw check var:" $check
# echo -e "Raw installed var:" $installed

#
# Test Names -------------------------
#
if [ "$c_base" != "$i_base" ]
then
continue # skip to next installed
fi

# name matched - descend here
#
if [ "$c_arch" = "$i_arch" ]
then
rpm_base_match=1
if [ "$report" = "all" ]
then
echo -e "\nNames MATCH: $c_base $c_arch"
fi
#
# Name Match, Test Versions
#
if [ "$i_version" = "$c_version" ]
then
echo -e "Versions MATCH\n(Req)$required_file: $c_version $c_arch\n(Local)$installed_file: $i_version $i_arch"

else # Versions Mis-Match
echo -e "Versions MIS-MATCH\n(Req)$required_file: $c_version $c_arch\n(Local)$installed_file: $i_version $i_arch"

if [ "$pause_mode" = "1" ]
then
echo "Paused: Press Enter To Continue"
read dummy
fi
fi # if versions don't match
break
fi # if arch match

done # next $installed in installed_rpms

if [ "$rpm_base_match" = "0" ]
then
echo -e "----------------------------"
echo -e "Missing RPM: \nName: $c_base \nArch: $c_arch\nVer: $c_version"
if [ "$pause_mode" = "1" ]
then
echo "Paused: Press Enter To Continue"
read dummy
fi
fi # if versions don't match

if [ "$verbose" = "1" ]
then
echo -e "----------------------------"
fi

done # next $check in check_rpms

unset installed_rpms
unset check_rpms

exit 0
Reply With Quote  
Join Date: May 2004
Posts: 10
Reputation: ajcamp is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
ajcamp ajcamp is offline Offline
Newbie Poster

Re: comparing versions

  #6  
Apr 5th, 2007
By the way, I'd be
VERY INTERESTED IN IMPROVEMENTS TO THIS SCRIPT.

Thanks
AJ
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC