Issue
So, I'm trying out an update (upgrade) script for CentOS
I have a Virtualbox VM for testing, on which I have a snapshot to which I can roll back
The script is written in dash (not bash) These are the lines that matter in my script:
HOLDPKGS=(kernel python)
The following loop adds strings nicely
for paket in ${HOLDPKGS[*]}
do
HOLDSTRING="--exclude=\"$paket*\" $HOLDSTRING"
done
Here lies the problem:
yum $HOLDSTRING -y update >> "$UPGRADE_LOGFILE" 2>&1
When I run the script with sh -x < scriptname >, this is the output (that matters):
+ HOLDSTRING='--exclude="python*" --exclude="kernel*" '
++ yum '--exclude="python*"' '--exclude="kernel*"' -y update
It finishes the update without errors, and no warnings regarding the syntax.
Yum completely ignores the exclude directives. This is what i'm seeing in the log:
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
I tried doing this:
echo yum $HOLDSTRING -y update >> "$UPGRADE_LOGFILE" 2>&1
And pasting the output:
yum --exclude="python*" --exclude="kernel*" -y update
into the shell. That finished nicely (ignored kernel & 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
As you can see, in the lower example, we don't have the kernel packages, which is what we want.
Does anyone see what i'm doing wrong? :/
P.S. I have just tried running the script within a bash environment, and the problem persists :/
Solution
The problem is your quotes. There is no package matching "kernel*"
, but there is a package matching kernel*
. But you should be using arrays anyway.
HOLDARR=()
for paket in ${HOLDPKGS[*]}
do
HOLDARR+=(--exclude="$paket*")
done
yum "${HOLDARR[@]}" -y update
Answered By - Ignacio Vazquez-Abrams