Bug 1381531

Summary: generated for loop snippet beside pcs commands gives syntax error if executed from file
Product: Red Hat Enterprise Linux 7 Reporter: Miroslav Lisik <mlisik>
Component: clufterAssignee: Jan Pokorný [poki] <jpokorny>
Status: CLOSED ERRATA QA Contact: cluster-qe <cluster-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.3CC: mlisik
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: clufter-0.75.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1381572 (view as bug list) Environment:
Last Closed: 2017-08-01 23:06:21 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:
Bug Depends On: 1387424    
Bug Blocks:    

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