0

I have a command that will have multiple lines as output. i will need to use each line as a source to another Command to process it. i am trying to assign a variable and loop through it, but it fails

Here is the output from command line

r_mqsc -m ABCD -r "DIS CHL(*) WHERE(SSLCIPH EQ TLS_RSA_WITH_AES_256_CBC_SHA)" -l |awk '/Connected/,0'|grep -v Connected |awk -F'SSLCIPH' '{print $1}'

 CHANNEL(TO.MQ95XCAT02.SSL) CHLTYPE(CLUSRCVR)
 CHANNEL(TO.MQ95XRB01.SSL) CHLTYPE(CLUSSDR)
 CHANNEL(TO.MQ95XRC01.SSL) CHLTYPE(CLUSSDR)
 CHANNEL(TO.MQ95XRL01.SSL) CHLTYPE(CLUSSDR)
 CHANNEL(TO.MQ95XRN01.SSL) CHLTYPE(CLUSSDR)
 CHANNEL(TO.XA.MQ95XCAT02.SSL) CHLTYPE(CLUSRCVR)
 CHANNEL(TO.XB.MQ95XCAT02.SSL) CHLTYPE(CLUSRCVR)
 CHANNEL(TO.XN.MQ95XCAT02.SSL) CHLTYPE(CLUSRCVR)

Now each of these line (complete line as is) need to be input to another command

like this

r_mqsc -m ABCD -r "ALTER $VARIABLE SSLCIPH('123_ABC_XYZ')" -l

Here is my script, which is failing

_chl="$(r_mqsc -m MQ95XCAT02 -r "DIS CHL(*) WHERE(SSLCIPH EQ TLS_RSA_WITH_AES_256_CBC_SHA)" -l |awk '/Connected/,0'|grep -v Connected |awk -F'SSLCIPH' '{print $1}')"
chlcnt=$(r_mqsc -m MQ95XCAT02 -r "DIS CHL(*) WHERE(SSLCIPH EQ TLS_RSA_WITH_AES_256_CBC_SHA)" -l |awk '/Connected/,0'|grep -v Connected |awk -F'SSLCIPH' '{print $1}'|wc -l)
echo "$_chl"
set -A strqmgrs ${_chl}
i=$chlcnt
arrayindex=0
while [ i -ne 0 ]
do
 chl=${strqmgrs[$arrayindex]}

r_mqsc -m MQ95XCAT02 -r "ALTER $chl SSLCIPH('TLS_RSA_WITH_AES_256_CBC_SHA256')" -l

i=$((i-1))
 arrayindex=$((arrayindex+1))
done

the $chl variable is coming out like this

ALTER CHLTYPE -- > note it is just taking the word CHLTYPE in the actual output line but not the entire line.

2

Don't write bash scripts the way you would write C code (nor vice versa).

cmd |\
while IFS= read -r line
do
  ...
done
0

if you need to keep variables set in the loop do it like this:

while read -r line 
do
  stuff

done < <( **command-line** )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.