Bug 1824961

Summary: /etc/cron.daily/rhsmd evaluates non-zero string incorrectly
Product: Red Hat Enterprise Linux 7 Reporter: matthew.f.ludwig
Component: subscription-managerAssignee: candlepin-bugs
Status: CLOSED DUPLICATE QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.8CC: dmilhuisen, redakkan
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-24 14:47:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description matthew.f.ludwig 2020-04-16 18:15:49 UTC
Description of problem:
After performing updates to a RH7 system, an error occurs when /etc/cron.daily/rhsmd runs.  The test for a string of non-zero length is evaluating to true, but no variable is returned from the grep statement.  It should perform the alternate statement, setting rhsmd_timeout=300.  Instead, it attempts to run a sleep command with no operand and fails.  The rhsm.conf.rpmnew file was created, but e use a modified rhsm.conf file for a proxy.

Below is output of error message:

Date: Thu, 16 Apr 2020 03:44:24 +0000 (GMT)

/etc/cron.daily/rhsmd:

sleep: missing operand
Try 'sleep --help' for more information.
/etc/cron.daily/rhsmd: line 19: 32461 Terminated              /usr/libexec/rhsmd -s

Below is the contents of the rhsmd script:

config=$(grep -E "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")
if [ -n $config ]; then
  rhsmd_timeout=$config
else
  rhsmd_timeout=300
fi

/usr/libexec/rhsmd -s &
sleep $rhsmd_timeout;

ps_check=$(pgrep -f '/usr/libexec/rhsmd')
if [ -n "$ps_check" ]; then
  pkill -f '/usr/libexec/rhsmd' >/dev/null 2>&1
  logger -t rhsmd -p user.warn "rhsmd process exceeded runtime and was killed." >/dev/null 2>&1
fi

If the string being tested were enclosed in quotation marks, it would evaluate correctly.

config=$(grep -E "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")
if [ -n "$config" ]; then
  rhsmd_timeout=$config
else
  rhsmd_timeout=300
fi

/usr/libexec/rhsmd -s &
sleep $rhsmd_timeout;

ps_check=$(pgrep -f '/usr/libexec/rhsmd')
if [ -n "$ps_check" ]; then
  pkill -f '/usr/libexec/rhsmd' >/dev/null 2>&1
  logger -t rhsmd -p user.warn "rhsmd process exceeded runtime and was killed." >/dev/null 2>&1
fi


Version-Release number of selected component (if applicable):
RHEL 7.8


How reproducible:
Always

Steps to Reproduce:
1. Execute /etc/cron.daily/rhsmd
2.
3.

Actual results:
sleep: missing operand

Expected results:
execute rhsmd -s


Additional info:

Comment 2 Rehana 2020-04-24 14:47:23 UTC

*** This bug has been marked as a duplicate of bug 1823780 ***