yum should error when a package is not available

As you’ve found, this behaviour changed between RHEL 5 and 6 (see https://bugzilla.redhat.com/show_bug.cgi?id=736694 for some discussion). From that link, checking the return code of yum info <pkg> should allow you to abort your script as required. Something like:

# Set a variable containing the packages to install:
pkgs_to_install="another_package.x86_64 some_package.x86_64"

# Loop over the packages in the list:
for pkg in ${pkgs_to_install}; do
  # Stop executing if at least one package isn't available:
  yum info ${pkg} >> /dev/null 2>&1 || exit
done

# Continue running your original script:
yum -y install ${pkgs_to_install} && run_my_script

Leave a Comment