Bug 1381531 - generated for loop snippet beside pcs commands gives syntax error if executed from file
Summary: generated for loop snippet beside pcs commands gives syntax error if executed...
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: clufter
Version: 7.3
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Jan Pokorný [poki]
QA Contact: cluster-qe@redhat.com
URL:
Whiteboard:
Keywords:
Depends On: 1387424
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-10-04 11:44 UTC by Miroslav Lisik
Modified: 2017-08-01 23:06 UTC (History)
1 user (show)

(edit)
Clone Of:
: 1381572 (view as bug list)
(edit)
Last Closed: 2017-08-01 23:06:21 UTC


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:2198 normal SHIPPED_LIVE clufter bug fix and enhancement update 2017-08-01 19:41:26 UTC

Description Miroslav Lisik 2016-10-04 11:44:05 UTC
Description of problem:
Clufter generates shell's for-loop snippet beside pcs commands. If it is executed from file then shell gives syntax error message. 


Version-Release number of selected component (if applicable):
clufter-cli-0.59.5-2.el7

How reproducible:
always

Steps to Reproduce:
1. Generate pcs commands from current cluster configuration by clufter:

For example with command:
clufter pcs2pcscmd --batch --quiet --silent --text-width=-1

2. Extract for-loop snippet into file:

[root@virt-024 ~]# cat snippet.sh 
for l in $( comm -12 \
  <( python -m json.tool /var/lib/pcsd/pcs_users.conf | sed -n 's|^\s*"[^"]\+":\s*"\([0-9a-f-]\+\)".*|\1|1p' | sort ) \
  <( python -m json.tool /var/lib/pcsd/tokens | sed -n 's|^\s*"[^"]\+":\s*"\([0-9a-f-]\+\)".*|\1|1p' | sort ) ) @SENTINEL@ ; do grep -Eq \
  "$( python -m json.tool /var/lib/pcsd/tokens | sed -n "s|^\s*\"\([^\"]\+\)\":\s*\"${l}\".*|\1|1p" )" - <<<' virt-024 virt-027' && break ; false ; done || { echo 'WARNING: cluster being created ought to include this very local machine' \
  ; read -p 'Do you want to continue [yN] (60s timeout): ' -t 60 || : ; test "${REPLY}" = y || kill -INT "$$" ; }

3. Run it by shell:

[root@virt-024 ~]# sh file.sh 
file.sh: command substitution: line 1: syntax error near unexpected token `('
file.sh: command substitution: line 1: `cat \<(/var/lib/pcsd/pcs_users.conf) \<(/var/lib/pcsd/tokens)'

Actual results:
Shell gives syntax error.

Expected results:
Execution without syntax error.

Comment 1 Miroslav Lisik 2016-10-04 11:55:05 UTC
Correct 3rd step should be:

[root@virt-024 ~]# sh snippet.sh 
snippet.sh: command substitution: line 6: syntax error near unexpected token `('
snippet.sh: command substitution: line 6: ` comm -12   <( python -m json.tool /var/lib/pcsd/pcs_users.conf | sed -n 's|^\s*"[^"]\+":\s*"\([0-9a-f-]\+\)".*|\1|1p' | sort )   <( python -m json.tool /var/lib/pcsd/tokens | sed -n 's|^\s*"[^"]\+":\s*"\([0-9a-f-]\+\)".*|\1|1p' | sort ) )'

Comment 3 Jan Pokorný [poki] 2016-12-12 15:22:45 UTC
Miro,

the error you observe comes from the fact that you are trying to run
bash-extended shell syntax (process substitution in particular) with
/bin/sh, i.e., a POSIX mode of the shell.  That means that you should
have used /bin/bash instead in [comment 0].

I do not mean to make do without that construct (the equivalent would
be a bigger, less readable code), but instead, I decided to put explicit
shebangs at the beginning of any shell-like output so as to make the
intended interpreter clear:

https://pagure.io/clufter/c/00927b704c78023096e1004a31869085f659def7?branch=next
https://pagure.io/clufter/c/8c1bb903faa198246c15a261af4fe6dd5f8d5df1?branch=next
https://pagure.io/clufter/c/4667896ce5b3ffb839e69403819d3d9331d079d8?branch=next

Do you consider this solution sufficient?

Comment 4 Miroslav Lisik 2017-01-20 17:32:57 UTC
Yes, I consider this solution sufficient. Shebangs inform users what kind of shell to use.

Comment 5 Jan Pokorný [poki] 2017-02-02 15:37:17 UTC
Already fixed in upstream, since v0.59.7.

Comment 9 errata-xmlrpc 2017-08-01 23:06:21 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:2198


Note You need to log in before you can comment on or make changes to this bug.