Project

General

Profile

Actions

Bug #16494

closed

[Missing Report #0] probably due to variable in script

Added by Matthew Laquerbe over 4 years ago. Updated about 1 year ago.

Status:
Rejected
Priority:
N/A
Assignee:
-
Category:
Web - Technique editor
Severity:
Minor - inconvenience | misleading | easy workaround
UX impact:
User visibility:
Getting started - demo | first install | Technique editor and level 1 Techniques
Effort required:
Priority:
0
Name check:
To do
Fix check:
To do
Regression:

Description

Hi,

I had a file to put that contains some batch lines. For any reason, one specific block is causing a "[Missing Report #0] when the policy is executed by Rudder. Here the block that is causing the issue

if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then
DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
fi

To bypass it, i created another variable containing the whole ${BASH_REMATCH[X]} line like this :
REMATCH="${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}"
if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" $REMATCH) fi

and now it works.

Rudder's version 6.0.0 (not in the target version list)

Actions #1

Updated by Matthew Laquerbe over 4 years ago

Complete script that returns the issue :
@[ -r /etc/update-motd.d/lsb-release ] && . /etc/update-motd.d/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi

re='(.*\()(.*)(\).*)'
if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then
DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" "${BASH_REMATCH1}" "${BASH_REMATCH2}" "${BASH_REMATCH3}")
fi

echo -e " "$DISTRIB_DESCRIPTION "(kernel "$(uname -r)")\n"

printf "DISTRIB_DESCRIPTION=\"%s\"" "$(lsb_release -s -d)" > /etc/update-motd.d/lsb-release &@

Complete modified script that is working

@[ -r /etc/update-motd.d/lsb-release ] && . /etc/update-motd.d/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi

re='(.*\()(.*)(\).*)'
REMATCH="${BASH_REMATCH1}" "${BASH_REMATCH2}" "${BASH_REMATCH3}"
if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" $REMATCH) fi

echo -e " "$DISTRIB_DESCRIPTION "(kernel "$(uname -r)")\n"

printf "DISTRIB_DESCRIPTION="%s"" "$(lsb_release -s -d)" > /etc/update-motd.d/lsb-release &@

Actions #2

Updated by François ARMAND over 4 years ago

  • User visibility set to Getting started - demo | first install | Technique editor and level 1 Techniques
  • Priority changed from 0 to 50

Thanks for reporting, and thanks for letting everyone knows about the workaround!

We are going to try to reproduce and undertand why it's happening.

Actions #3

Updated by Benoît PECCATTE over 4 years ago

I don't understand your regex + printf :
  • You match the whole string by just splitting it at the parenthesis: re='(.*\()(.*)(\).*)'
  • Then you simply concatenate it using printf which should give you the exact same string.

Moreover, please note that in your non working example, you are calling printf with 5 %s whereas you only give 3 parameters.

In the working example:
  • you are calling printf with 5 %s and you give it an undefined number of parameters (4 for a debian)
  • the REMATCH variable should be empty since it is created before BASH_REMATCH exists since the if match is done on the line below
Actions #4

Updated by Félix DALLIDET over 4 years ago

Hi, it seems that you are trying to write this script down to a given file using Rudder.
This is definitely possible and should not lead to any missing report, so what happens here is:

Rudder has its own variable system, they are used with the syntax "${...}" (or for old compatibility "$(...)").
So when trying to write down your script, Rudder thinks that your lines using one of these patterns are call to Rudder variables that are not yet defined and so,
because of the logic of the rudder-agent, in this specific case, will skip the complete application of your configuration since its only content (the text block that you are trying to
enforce) is not fully defined.

This skip mechanism is not a common case and should not happen in most cases.

So, to be sure that Rudder will not try to interpret your bash variables you can use some Rudder special variables dedicated to this cases: https://docs.rudder.io/reference/6.0/reference/variables.html
The special variable to write down a "$" can be used with "${const.dollar}" and should be used almost everytime your are using a "$" sign which is not intended to call a Rudder variable.

Replacing all your "${<something>}" and "$(<something else>)" by "${const.dollar}{<something>}" and "${const.dollar}(<something else>)" should do the trick and fix your issue.
Try replacing your input by:

[ -r /etc/update-motd.d/lsb-release ] && . /etc/update-motd.d/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
DISTRIB_DESCRIPTION=${const.dollar}(lsb_release -s -d)
fi

re='(.*\()(.*)(\).*)'
if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then
DISTRIB_DESCRIPTION=${const.dollar}(printf "%s%s%s%s%s" "${const.dollar}{BASH_REMATCH1}" "${const.dollar}{BASH_REMATCH2}" "${const.dollar}{BASH_REMATCH3}")
fi

echo -e " "$DISTRIB_DESCRIPTION "(kernel "${const.dollar}(uname -r)")\n" 

printf "DISTRIB_DESCRIPTION="%s"" "${const.dollar}(lsb_release -s -d)" > /etc/update-motd.d/lsb-release &

And tell me if it worked as expected

Actions #5

Updated by Vincent MEMBRÉ over 4 years ago

  • Target version changed from 6.0.2 to 6.0.3
Actions #6

Updated by Matthew Laquerbe over 4 years ago

for Benoit comment, this is correct the printf was wrong, and also this code was not executed anyway so i removed it. Anyway the issue is not the script itself since it is working if i put the exact same thing even with the error in the code directly on the server without using Rudder.

for Félix comment, i tried your suggestion but same issue. seems to be a combination of special characters in this line that is causing the issue but i did not figure out which one.

I just removed this line, but if you want to debug just add a new step to create a file and put this specific line
DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}") even if code point of view it will do nothing, it is supposed to fill the file without any issue because for Rudder it is a simple file.

thanks for your support.

Actions #7

Updated by Vincent MEMBRÉ about 4 years ago

  • Target version changed from 6.0.3 to 6.0.4
Actions #8

Updated by Vincent MEMBRÉ about 4 years ago

  • Target version changed from 6.0.4 to 6.0.5
Actions #9

Updated by Vincent MEMBRÉ almost 4 years ago

  • Target version changed from 6.0.5 to 6.0.6
  • Priority changed from 50 to 49
Actions #10

Updated by Vincent MEMBRÉ almost 4 years ago

  • Target version changed from 6.0.6 to 6.0.7
  • Priority changed from 49 to 48
Actions #11

Updated by Vincent MEMBRÉ almost 4 years ago

  • Target version changed from 6.0.7 to 6.0.8
  • Priority changed from 48 to 47
Actions #12

Updated by Vincent MEMBRÉ over 3 years ago

  • Target version changed from 6.0.8 to 6.0.9
  • Priority changed from 47 to 46
Actions #13

Updated by Vincent MEMBRÉ over 3 years ago

  • Target version changed from 6.0.9 to 6.0.10
  • Priority changed from 46 to 45
Actions #14

Updated by Vincent MEMBRÉ over 3 years ago

  • Target version changed from 6.0.10 to 798
  • Priority changed from 45 to 44
Actions #15

Updated by Benoît PECCATTE almost 3 years ago

  • Target version changed from 798 to 6.1.14
  • Priority changed from 44 to 42
Actions #16

Updated by Vincent MEMBRÉ almost 3 years ago

  • Target version changed from 6.1.14 to 6.1.15
Actions #17

Updated by Vincent MEMBRÉ over 2 years ago

  • Target version changed from 6.1.15 to 6.1.16
Actions #18

Updated by Vincent MEMBRÉ over 2 years ago

  • Target version changed from 6.1.16 to 6.1.17
Actions #19

Updated by Vincent MEMBRÉ over 2 years ago

  • Target version changed from 6.1.17 to 6.1.18
Actions #20

Updated by Vincent MEMBRÉ over 2 years ago

  • Target version changed from 6.1.18 to 6.1.19
Actions #21

Updated by Vincent MEMBRÉ about 2 years ago

  • Target version changed from 6.1.19 to 6.1.20
Actions #22

Updated by Vincent MEMBRÉ almost 2 years ago

  • Target version changed from 6.1.20 to 6.1.21
Actions #23

Updated by Vincent MEMBRÉ almost 2 years ago

  • Target version changed from 6.1.21 to old 6.1 issues to relocate
Actions #24

Updated by Alexis Mousset about 1 year ago

  • Status changed from New to Rejected
  • Priority changed from 42 to 0
Actions

Also available in: Atom PDF