Is there a good way to use Yum to test if something is installed (true of false) and then use that answer in a Bash script?

link|improve this question

79% accept rate
feedback

3 Answers

It's faster to query using rpm instead.

if rpm -q somepackage &> /dev/null
then
   ...
fi
link|improve this answer
1  
You can make that even faster with rpm -q somepackage --nodigest --nosignatures. – mattdm Dec 13 '10 at 2:59
feedback

if you know a bit of python you could do it very easy - yum has pre/post filters that can be enabled you can even make your own plugin.

from shell just look for any lines that will be the output from your query.

pack = yum info package | wc -l

if [ "$pack" != '' ];

then

do something

else

do something else

fi

link|improve this answer
feedback

I typically test for the results of the package, usually a file on the file-system that is installed. Something like:

[ ! -f /usr/bin/apg ] && yum -y install apg

This requires no RPM database lookup, so it's very light-weight.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.