Skip to content

Commit 08fe83f

Browse files
authored
Merge pull request #48 from EncoreTechnologies/bugfix/bash-errors
Fixing bug in update_rh.sh where yum errors were being ignored
2 parents 865b3ff + 2b14659 commit 08fe83f

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ All notable changes to this project will be documented in this file.
2525
config value wasn't being honored. (Bug Fix)
2626

2727
Contributed by Nick Maludy (@nmaludy)
28-
28+
29+
* Fixed a bug in `patching::update` task on RHEL where errors in the `yum` command we're
30+
being reported due to the use of a `|`. Now we check `$PIPESTATUS[0]` instead of `$?`. (Bug Fix)
31+
32+
Contributed by Nick Maludy (@nmaludy)
33+
2934
* Added new configuration options:
3035
* `patching_reboot_wait`: Parameter controls the `reboot_wait` option for the number of seconds
3136
to wait between reboots. Default = 300

files/bash/update_rh.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ EOF
6767
STATUS=0
6868

6969
## Yum package manager
70-
YUM_UPDATE=$(yum -y update $PACKAGES | tee -a "$LOG_FILE")
70+
#
71+
# Because we're using '| tee' inside a $(), we can't just check $? after the command
72+
# as it will return the exit code of the LAST thing in the pipe,
73+
# instead we really want to return code of the `yum` command (first thing in the pipe).
74+
# For this to work, we need to exit the command in the $() with a value
75+
# from the $PIPESTATUS array to get access to the `yum` command's return value.
76+
# Now, the exit status for the $() will be whatever the exit status is for `yum` instead
77+
# of the exit status of `tee`.
78+
YUM_UPDATE=$(yum -y update $PACKAGES | tee -a "$LOG_FILE"; exit ${PIPESTATUS[0]})
7179
STATUS=$?
7280

7381
# check if packages were updated or not

0 commit comments

Comments
 (0)