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
MAKEDELTARPM(8) 					      System Manager's Manual						   MAKEDELTARPM(8)

NAME
makedeltarpm - create a deltarpm from two rpms SYNOPSIS
makedeltarpm [-v] [-V version] [-z compression] [-m mbytes] [-s seqfile] [-r] [-u] oldrpm newrpm deltarpm makedeltarpm [-v] [-V version] [-z compression] [-s seqfile] [-u] -p oldrpmprint oldpatchrpm oldrpm newrpm deltarpm DESCRIPTION
makedeltarpm creates a deltarpm from two rpms. The deltarpm can later be used to recreate the new rpm from either filesystem data or the old rpm. Use the -v option to make makedeltarpm more verbose about its work (use it twice to make it even more verbose). If you want to create a smaller and faster to combine "rpm-only" deltarpm which does not work with filesystem data, specify the -r option. makedeltarpm normally produces a V3 format deltarpm, use the -V option to specify a different version if desired. The -z option can be used to specify a different compression method, the default is to use the same compression method as used in the new rpm. The -s option makes makedeltarpm write out the sequence id to the specified file seqfile. If you also use patch rpms you should use the -p option to specify the rpm-print of oldrpm and the created patch rpm. This option tells makedeltarpm to exclude the files that were not included in the patch rpm but are not byteswise identical to the ones in oldrpm. makedeltarpm can also create an "identity" deltarpm by adding the -u switch. In this case only one rpm has to be specified. An identity deltarpm can be useful to just replace the signature header of a rpm or to reconstruct a rpm from the filesystem. MEMORY CONSIDERATIONS
makedeltarpm normally needs about three to four times the size of the rpm's uncompressed payload. You can use the -m option to enable a sliding block algorithm that needs mbytes megabytes of memory. This trades memory usage with the size of the created deltarpm. Furthermore, the uncompressed deltarpm payload is currently also stored in memory when this option is used, but it tends to be small in most cases. SEE ALSO
applydeltarpm(8) combinedeltarpm(8) AUTHOR
Michael Schroeder <mls@suse.de> Jul 2010 MAKEDELTARPM(8)
All times are GMT -4. The time now is 09:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy