11

I have a shell script which checks if there is an internet connection (by pinging google), and then calls

yum install packageA packageB --assumeyes 

How would I confirm that the packages were installed (or were already installed)? Do I make another yum call and parse the output (I presume this gets very complicated if the system is in another language)?

2
  • You could grep or parse /var/log/yum.log Commented Dec 9, 2011 at 14:42
  • Setting LC_ALL=C should switch to English. Commented Dec 9, 2011 at 14:44

3 Answers 3

13

I've used the following method, which might not be foolproof, but seems to work:

Assuming the variable PACKAGES contains the list of packages you want to install, then:

  1. Run yum -y install $PACKAGES (I assume if this is a script, you really want to pass -y to avoid prompting).
  2. Check its exit status in order to detect some failure conditions.
  3. Run rpm --query --queryformat "" $PACKAGES, which will output nothing for each package that was installed successfully, and will output package <name> is not installed for each failure.
  4. Check its exit status, which appears to be the number of packages that were not successfully installed, i.e. will be 0 on success as usual.

This will only work if PACKAGES contains plain package names that yum is expected to find in a repository, not if it contains other things that yum accepts like URLs, file names or Provides: names.

Sign up to request clarification or add additional context in comments.

Comments

7

Based on this random post, it looks like yum returns an error code to the shell. You can test this out by running a command and then immediately (as the next command) doing:

echo $? 

That will print the previous command's return code. Success should be 0, failure of some kind nonzero. But that's just a guess since I don't have a box accessible to me at the moment. :)

2 Comments

That should be how it works. My version of yum exits with success even on certain failures; yum install non-existant-package && echo "I think that went well"
As noted above, there are a number of cases where yum returns 0 even though I would consider it to have failed, e.g. you specified a package name but that package could not be found in any configured repository or you specified a file name but the file was not found. yum's exit status is just not that useful.
6

By ping google.com does not ensure the yum repo you trying to connect is available

The command to check whether a package is already installed :-

yum list installed PACKAGE_NAME 

2 Comments

thanks ajreal -- I was just pinging google to see if dns was working and if there was connectivity.
Although this doesn't directly answer the question, it answers my question! +1 for you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.