【问题标题】:yum update ignores exclude when called in scriptyum update 在脚本中调用时忽略排除
【发布时间】:2013-01-09 13:01:11
【问题描述】:

所以,我正在尝试 CentOS 的更新(升级)脚本

我有一个用于测试的 Virtualbox VM,我有一个可以回滚到的快照

脚本是用破折号(不是 bash)编写的 这些是我的脚本中重要的行:

HOLDPKGS=(kernel python)

下面的循环很好地添加了字符串

for paket in ${HOLDPKGS[*]}
do
  HOLDSTRING="--exclude=\"$paket*\" $HOLDSTRING"
done

问题出在这里:

yum $HOLDSTRING -y update >> "$UPGRADE_LOGFILE" 2>&1

当我使用 sh -x 运行脚本时,这是输出(很重要):

+ HOLDSTRING='--exclude="python*" --exclude="kernel*" '
++ yum '--exclude="python*"' '--exclude="kernel*"' -y update

它在没有错误的情况下完成更新,并且没有关于语法的警告。

Yum 完全忽略了排除指令。这是我在日志中看到的:

Dependencies Resolved

================================================================================
 Package                 Arch   Version                           Repository
                                                                           Size
================================================================================
Installing:
 kernel                  x86_64 2.6.32-279.19.1.el6               updates  25 M
Updating:
 cpio                    x86_64 2.10-11.el6_3                     updates 192 k
 dhclient                x86_64 12:4.1.1-31.0.1.P1.el6.centos.1   updates 317 k
 dhcp-common             x86_64 12:4.1.1-31.0.1.P1.el6.centos.1   updates 141 k
 dracut                  noarch 004-284.el6_3.1                   updates 112 k
 dracut-kernel           noarch 004-284.el6_3.1                   updates  21 k
 glibc                   x86_64 2.12-1.80.el6_3.6                 updates 3.8 M
 glibc-common            x86_64 2.12-1.80.el6_3.6                 updates  14 M
 initscripts             x86_64 9.03.31-2.el6.centos.1            updates 935 k
 kernel-firmware         noarch 2.6.32-279.19.1.el6               updates 8.7 M
 krb5-libs               x86_64 1.9-33.el6_3.3                    updates 713 k
 libblkid                x86_64 2.17.2-12.7.el6_3                 updates 112 k
 libssh2                 x86_64 1.2.2-11.el6_3                    updates  75 k
 libudev                 x86_64 147-2.42.el6                      updates  75 k
 libuuid                 x86_64 2.17.2-12.7.el6_3                 updates  65 k
 mysql-libs              x86_64 5.1.66-2.el6_3                    updates 1.2 M
 nspr                    x86_64 4.9.1-2.el6_3                     updates 111 k
 nss                     x86_64 3.13.5-1.el6_3                    updates 763 k
 nss-sysinit             x86_64 3.13.5-1.el6_3                    updates  32 k
 nss-tools               x86_64 3.13.5-1.el6_3                    updates 729 k
 nss-util                x86_64 3.13.5-1.el6_3                    updates  53 k
 openldap                x86_64 2.4.23-26.el6_3.2                 updates 262 k
 openssl                 x86_64 1.0.0-25.el6_3.1                  updates 1.4 M
 python                  x86_64 2.6.6-29.el6_3.3                  updates 4.8 M
 python-libs             x86_64 2.6.6-29.el6_3.3                  updates 623 k
 redhat-logos            noarch 60.0.14-12.el6.centos             updates  15 M
 selinux-policy          noarch 3.7.19-155.el6_3.14               updates 1.3 M
 selinux-policy-targeted noarch 3.7.19-155.el6_3.14               updates 2.6 M
 sudo                    x86_64 1.7.4p5-13.el6_3                  updates 423 k
 tzdata                  noarch 2012j-1.el6                       updates 453 k
 udev                    x86_64 147-2.42.el6                      updates 361 k
 util-linux-ng           x86_64 2.17.2-12.7.el6_3                 updates 1.5 M

我试过这样做:

echo yum $HOLDSTRING -y update >> "$UPGRADE_LOGFILE" 2>&1

并粘贴输出:

yum --exclude="python*" --exclude="kernel*" -y update

进入外壳。完成得很好(忽略了内核和 python)

Dependencies Resolved

================================================================================
 Package                 Arch   Version                           Repository
                                                                           Size
================================================================================
Updating:
 cpio                    x86_64 2.10-11.el6_3                     updates 192 k
 dhclient                x86_64 12:4.1.1-31.0.1.P1.el6.centos.1   updates 317 k
 dhcp-common             x86_64 12:4.1.1-31.0.1.P1.el6.centos.1   updates 141 k
 dracut                  noarch 004-284.el6_3.1                   updates 112 k
 dracut-kernel           noarch 004-284.el6_3.1                   updates  21 k
 glibc                   x86_64 2.12-1.80.el6_3.6                 updates 3.8 M
 glibc-common            x86_64 2.12-1.80.el6_3.6                 updates  14 M
 initscripts             x86_64 9.03.31-2.el6.centos.1            updates 935 k
 krb5-libs               x86_64 1.9-33.el6_3.3                    updates 713 k
 libblkid                x86_64 2.17.2-12.7.el6_3                 updates 112 k
 libssh2                 x86_64 1.2.2-11.el6_3                    updates  75 k
 libudev                 x86_64 147-2.42.el6                      updates  75 k
 libuuid                 x86_64 2.17.2-12.7.el6_3                 updates  65 k
 mysql-libs              x86_64 5.1.66-2.el6_3                    updates 1.2 M
 nspr                    x86_64 4.9.1-2.el6_3                     updates 111 k
 nss                     x86_64 3.13.5-1.el6_3                    updates 763 k
 nss-sysinit             x86_64 3.13.5-1.el6_3                    updates  32 k
 nss-tools               x86_64 3.13.5-1.el6_3                    updates 729 k
 nss-util                x86_64 3.13.5-1.el6_3                    updates  53 k
 openldap                x86_64 2.4.23-26.el6_3.2                 updates 262 k
 openssl                 x86_64 1.0.0-25.el6_3.1                  updates 1.4 M
 redhat-logos            noarch 60.0.14-12.el6.centos             updates  15 M
 selinux-policy          noarch 3.7.19-155.el6_3.14               updates 1.3 M
 selinux-policy-targeted noarch 3.7.19-155.el6_3.14               updates 2.6 M
 sudo                    x86_64 1.7.4p5-13.el6_3                  updates 423 k
 tzdata                  noarch 2012j-1.el6                       updates 453 k
 udev                    x86_64 147-2.42.el6                      updates 361 k
 util-linux-ng           x86_64 2.17.2-12.7.el6_3                 updates 1.5 M

如您所见,在下面的示例中,我们没有我们想要的内核包。

有人看到我做错了什么吗? :/

附: 我刚刚尝试在 bash 环境中运行脚本,但问题仍然存在:/

【问题讨论】:

  • 为什么在你的非工作输出周围有单引号:++ yum '--exclude="python*"' '--exclude="kernel*"' -y update?这可能是罪魁祸首吗?
  • 嗯,不确定这是调试的分离参数的方式,还是我的错误代码......可能是后者:/

标签: shell scripting centos yum


【解决方案1】:

问题是你的报价。没有匹配"kernel*" 的包,但有匹配kernel* 的包。但是你should be using arrays anyway

HOLDARR=()
for paket in ${HOLDPKGS[*]}
do
  HOLDARR+=(--exclude="$paket*")
done

yum "${HOLDARR[@]}" -y update

【讨论】:

  • 你摇滚。你给我的 wiki 链接帮助了我一百万次。我想我还有很多东西要学,仍然:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-20
  • 2014-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多