yum update在脚本中调用时忽略exclude

问题描述 投票:0回答:1

所以,我正在为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 <scriptname>运行脚本时,这是输出(重要):

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

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

百胜彻底忽略了排除指令。这就是我在日志中看到的:

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环境中运行脚本,问题仍然存在:/

shell scripting centos yum
1个回答
1
投票

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

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

yum "${HOLDARR[@]}" -y update
© www.soinside.com 2019 - 2024. All rights reserved.