Check if rpm is installed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check if rpm is installed
# 1  
Old 02-24-2008
Check if rpm is installed

Hi all im hoping someone can help, i want to check if a rpm package is installed, if it is then display one text if not then another text, below is what i have got so far, im am very much a noob at this, as you can probably can see so if possible make it simple, and a big thankyou if you can help me please.

Quote:
#!/bin/bash


if [ $($rpm -qa flash-plugin) != "flash-plugin.i386 0:9.0.115.0-release" ] ; then
zenity --error \
--text="notgot"
else
zenity --error \
--text="got"
fi
# 2  
Old 02-24-2008
If its any help, a list of installed rpms is kept in /var/log/rpmpkgs
so i suppose its possible to check that instead of a rpm command but i havent a clue how to do that any help would be most grateful.
# 3  
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
# 4  
Old 02-25-2008
Thankyou so much,Smilie this has helped me alot,if you are a beautiful woman then big hugs and kisses as well Smilie if not then just a big thankyouSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question