centos – 当包裹不可用时,yum应该出错

前端之家收集整理的这篇文章主要介绍了centos – 当包裹不可用时,yum应该出错前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近在脚本中遇到了一个错误,我尝试执行以下操作:
yum -y install another_package.x86_64 some_package.x86_64 && run_my_script

该脚本在较新的CentOS上运行良好,但当我尝试在Cent OS 5上执行时,some_package.x86_64不可用.但不是错误和停止yum只是打印消息:

No package some_package.x86_64 available.

如何在这种情况下强制yum出错(IMO应该是默认值)以使我的脚本更健壮?

正如您所发现的,此行为在RHEL 5和6之间发生了变化(有关讨论,请参阅 https://bugzilla.redhat.com/show_bug.cgi?id=736694).从该链接,检查yum info< pkg>的返回代码应该允许您根据需要中止脚本.就像是:
# 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
原文链接:https://www.f2er.com/centos/373948.html

猜你在找的CentOS相关文章