•
•
•
•
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
![]() |
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.
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
----------------------------------------------
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
•
•
Join Date: May 2004
Posts: 10
Reputation:
Rep Power: 5
Solved Threads: 0
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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- No end to new versions? (Windows NT / 2000 / XP / 2003)
- Trojan.Bookmarker.gen/about:blank (Viruses, Spyware and other Nasties)
- Essay help:comparing two professions, Software Enginering and ? (Computer Science and Software Design)
Other Threads in the Shell Scripting Forum
- Previous Thread: samba server error
- Next Thread: Automating an FTP upload



Linear Mode