Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

It's faster to query using rpm instead.

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

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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