Sponsored Content
Full Discussion: Check if rpm is installed
Top Forums Shell Programming and Scripting Check if rpm is installed Post 302170163 by drl on Sunday 24th of February 2008 07:27:21 PM
Old 02-24-2008
Hi.

Regrettably, rpm does not return an exit status as do most commands (more correctly it seems to always return zero). This might be because it's too complex to simply decide "yes" or "no".

So one solution is to look at the output. We can do a compare very similar to the way you did, but checking for a string match, rather than strict equality, which can cause problems because of whitespace, among other things.

Here's an example:
Code:
#!/bin/bash -

# @(#) user1    Demonstrate rpm query.

uname -rv
bash --version
rpm --version

echo
P=${1?" must specify package name."}

rpm -qa "$P" > t1
my_size=$( wc -l < t1 )
echo " Size of report file is $my_size lines"

if [[ $( rpm -qa $P ) =~ ${P} ]]
# if [[ $( rpm -qa $P ) == *${P}* ]]
then
  echo " Package $P is installed."
else
  echo " Package $P not found."
fi

exit 0

Producing a success:
Code:
./user1 bash
2.6.22.17-0.1-default #1 SMP 2008/02/10 20:01:04 UTC
GNU bash, version 3.2.25(1)-release (i586-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
RPM version 4.4.2

 Size of report file is 1 lines
 Package bash is installed.

And a failure:
Code:
./user1 junk
2.6.22.17-0.1-default #1 SMP 2008/02/10 20:01:04 UTC
GNU bash, version 3.2.25(1)-release (i586-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
RPM version 4.4.2

 Size of report file is 0 lines
 Package junk not found.

You can look a the output from rpm on file t1. Both forms of the "if" seemed to work for me, and you can look through man bash or a tutorial to see the details on the "if" ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Linux

Failed dependencies of rpm / how does RPM check for ?

Hey, I've a problem installing a package. rpm -ivh brings the errors: libjvm.so is needed by libverify.so is needed by But I have installed the Java SDK like requested and the files are on the disk. But I have no idea how to find out, why rpm cann't find them. I have also... (2 Replies)
Discussion started by: mod
2 Replies

2. Shell Programming and Scripting

How to check if perl is installed?

Hi, i'm designing a unix script and i want to know if there is a shell command or a way to see if perl is installed in the system. thanks in advance! (5 Replies)
Discussion started by: kfad
5 Replies

3. AIX

How to check if a package is already installed?

Hi All, I want to check if the perl DBI package is already installed my AIX unix machine. is there any command to check this? Please help. Thanks, Am (2 Replies)
Discussion started by: am_yadav
2 Replies

4. Linux

RPM used to installed to get a partcular command

Hi, I have a query in linux and please find the details of it I have a command in linux and i want to know which rpm has provided that command. ie: if we take ifconfig command ,i want to know what is the rpm package used to get that command. Regards Arun.Kakarla (3 Replies)
Discussion started by: Arun.Kakarla
3 Replies

5. Shell Programming and Scripting

How to make RPM not write to RPM database if RPM fails to deploy?

How to make RPM not write to RPM database if RPM fails to deploy? IE I create an rpm spec file that contains the following if then exit 1 fi My rpm will fail at deployment, but if I do rpm -qa , I can see the rpm in the rpm db (3 Replies)
Discussion started by: 3junior
3 Replies

6. Red Hat

Trouble with installed / not installed rpm unixODBC/libodbc.so.1

Hey there, i run 1: on my server (RHEL 6) and getting response that the libodbc is not installed. If i use yum for installation, it tells me, there is no package like this ( 2: ). Since in the description of Definiens is mentioned that the Run-time dependency is unixODBC (libodbc.so.1), I assume... (2 Replies)
Discussion started by: rkirsten
2 Replies

7. Emergency UNIX and Linux Support

Problem when trying to remove a package using rpm command - error: package is not installed

Hello, i have installed a package by using the command sudo rpm -i filepackage.rpm package filepackage is already installed when i try to remove it, i get an error saying "is not installed": sudo rpm -e filepackage.rpm error: package filepackage is not installed How can... (4 Replies)
Discussion started by: g_p
4 Replies

8. Red Hat

How to check HDD Rpm?

Hello Can you help how can I check Hard Drive rpm. Thank you Jaydul (4 Replies)
Discussion started by: jaydul
4 Replies

9. Red Hat

How to create an rpm from installed files?

i would like to package up an rpm from pre-installed files, say i have a program called "widget" installed under "/opt/widget" /opt/widget/bin/* /opt/widget/lib/* /opt/widget/etc/* /opt/widget/log/* and i want to create an rpm from those already installed files, what would the spec file... (2 Replies)
Discussion started by: melixir
2 Replies

10. Shell Programming and Scripting

How to check if Autosys is installed?

How can I check if "Autosys" is installed on my Linux and Solaris servers ? I prefer Autosys instead of Crontab. (4 Replies)
Discussion started by: mohtashims
4 Replies
APPLYDELTARPM(8)					      System Manager's Manual						  APPLYDELTARPM(8)

NAME
applydeltarpm - reconstruct an rpm from a deltarpm SYNOPSIS
applydeltarpm [-v] [-p] [-r oldrpm] deltarpm newrpm applydeltarpm -c|-C deltarpm applydeltarpm [-c|-C] -s sequence applydeltarpm -i deltarpm DESCRIPTION
applydeltarpm applies a binary delta to either an old rpm or to on-disk data to re-create a new rpm. The old rpm can be specified with the -r option, if no rpm name is provided on-disk data is used. You can use -p to make applydeltarpm print the percentage of completion, or -v to make it more verbose about its operation. The second an third form can be used to check if the reconstruction is possible. It may fail if the on-disk data got changed (deltarpms are created in a way that config file changes do not matter) or the deltarpm does not match the rpm the delta was generated with. The -c option selects full (i.e. slow) on-disk checking, whereas -C only checks if the filesizes have not changed. Instead of a full deltarpm a sequence id can be given with the -s sequence option. Such an id contains all the information that is needed to do reconstruction checking. Finally information about a deltarpm can be printed with the -i option. MEMORY CONSIDERATIONS
applydeltarpm was written to work on systems with limited memory. It uses a paging algorithm to keep the size of in-core data low and not bring the system in an out-of-memory situation. EXIT STATUS
applydeltarpm returns 0 if the rpm could be recreated or the checking succeeded, it returns 1 and prints an error message to stderr if something failed. SEE ALSO
makedeltarpm(8), rpm(8) AUTHOR
Michael Schroeder <mls@suse.de> Feb 2005 APPLYDELTARPM(8)
All times are GMT -4. The time now is 10:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy