What could be the issue ?

Hi,

when i am trying below script

assume that below values are taken in code

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: aNlist.sh QMGR NAME MQREQ
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`
echo 'define nl('$NL_$2') like('$NL')'|runmqsc $1

i am getting below output from below command

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

Output from above code is

now i am trying to take backup from below command which is failing.

below command will take backup

define nl('$NL_$2') like('$NL')

I am trying to take back up as

but it is doing as

Where is the issue?

$NL_$2

uses a variable called NL_

$ NL_=6
$ NL=7
$ echo $NL_
6
$
$ echo ${NL}_
7_
$

when i use below command

echo 'define nl({'$NL_$2'}) like('$NL')'|runmqsc $1

i am getting below output

when i use below command

echo 'define nl('{$NL}_$2'}) like('$NL')'|runmqsc $1

but i don't want { and } as command can't run with it

i am looking for

---------- Post updated at 11:16 AM ---------- Previous update was at 11:09 AM ----------

Thanks, i got it how to apply your answer and it worked now.

1 Like

i am trying to append the existing one.. and add the value at the last for example

when i fire below command

 dis nl(RSB) 

output is

now i am trying to alter the namelist with below command

 alter nl(RSB) NAMES(ONE,TWO,THREE,$3) 

but i don't know how to edit the existing one and add $3 in the last.

Something like this?

awk '/^NAMES\(/ {a=1} a==1 {s0=s0 $0; if (/\)/) {sub("\)",","add"\)",s0); print s0; exit} }' add='$3' <output

Hi,

Below one is the script

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`
echo 'define NAMELIST('$NL'_'$2') like('$NL')'|runmqsc -e $1

When i run alterNamelist.sh like below

above code does the activity taking back up

till here i could do...

Now i want to do 2nd activity - editing existing by adding new names like below

below is command

dis NAMELIST(WORLD)

output of above one is

Now i want to edit "WORLD"'S property "NAMES"

When i do manually i do it like below

i am trying to do ALTER NAMELIST part by script.. I am failing to add + and ' and ,

Hi,

I didn't get any answers, i tried below one.
this script name is fr.sh

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`
echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names '|runmqsc $1

from below code i am getting output

echo 'dis nl('$NL') names '|runmqsc $1

OUTPUT

 dis nl(HOME_NL_NAMES) names
AMQ8550: Display namelist details.
   NAMELIST(HOME_NL_NAMES)
   NAMES(CLUS1
        ,CLUS2
        ,CLUS3)

Now below thing is i am trying to do

when i run my script like below

./fr.sh QM MQ123 CLUS4

it should do like below

alter NAMELIST(HOME_NL_NAMES) +
      DESCR(MQ123) +
      NAMES(CLUS1+
           ,CLUS2+
           ,CLUS3+
           ,CLUS4)

can some one suggest me to achive above one

It looks like your examples are a bit screwed up.
Is the script name fr.sh or alterNamelist.sh ?
Is the second parameter ( $2 ) MQ123 or HOME_NL_NAMES ?
Anyway, the following might be closer to what you want:

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

#NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`
#shorter, all in sed:
NL=`echo 'dis qmgr' | runmqsc $1 | sed -n 's/.*REPOSNL[^(]*(\([^)]*\)).*/\1/p'`

# Backup
echo 'define NAMELIST('$NL'_'$2') like('$NL')'|runmqsc -e $1

# Alter with $3
echo 'dis nl('$NL') names ' | runmqsc $1 | awk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
    sub("\)",","add"\)",s0)
    print "alter",nl,s0
    exit
  }
}' add="$3"

Yes both are same scripts.

When i run below code i got error.

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names ' | runmqsc $1 | awk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
    sub("\)",","add"\)",s0)
    print "alter",nl,s0
    exit
  }
}' add="$3

i got error

i removed " in last line of code and tried i got below error

1 Like

You missed the very last " !
Also, in Solaris the awk in /usr/bin/ is broken, please use nawk or /usr/xpg4/bin/awk

I modified as you suggested like below

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names ' | runmqsc $1 | nawk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
    sub("\)",","add"\)",s0)
    print "alter",nl,s0
    exit
  }
}' add="$3"

now i am getting below error

Oops, looks I have hit a bug in nawk.
Use /usr/xpg4/bin/awk, or change the line

       sub("\)",","add"\)",s0)

to

       sub( /\)/, ","add"\)", s0 )

i am getting below error.

code is

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names ' | runmqsc $1 | nawk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
sub( /\)/, ","add"\)", s0
print "alter",nl,s0
    exit
  }
}' add="$3"

Now you are missing the closing ) at the end of the line.

Thanks it is done almost but it is coming in below format

but i am looking here as

in the above one there should be space front of +. Space is required only in first line. value should start in new line followed by ,

---------- Post updated at 10:36 AM ---------- Previous update was at 06:34 AM ----------

command is coming but it is not executing..
below is the code

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names ' | runmqsc $1 | nawk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
sub( /\)/, ","add"\)", s0)
print "alter",nl,s0
    exit
  }
}' add="$3"

i ran script like below

./alterNamelist.sh QMGR MQ123 CLUS5

output is coming like below

below command is coming but not getting executed. I think i need to put it in echo

but i want it as like below

ALTER NAMELIST(CL.HOME_NL_NAMES) +
NAMES(CLUS1+
,CLUS2+
,CLUS3+
,CLUS4+
,CLUS5)

and it should execute

I think the 'alter ...' command is like the previous 'define ...' command, so needs to be piped to your application in order to execute?
... | runmqsc -e $1

Yes. but as there was S0 and bit of scripting. So i am not sure where to add this pipe. and actually i have given the alter namelist format which i am looking for in above.

alter name list we achived with your help is coming like below

alter NAMELIST(CL.HOME_NL_NAMES) NAMES(CLUS1 ,CLUS2 ,CLUS3 ,CLUS4,CLUS5) 

but what i am looking is like below

ALTER NAMELIST(CL.HOME_NL_NAMES) + (infront of + there should be one space)
DESCR('$2') +                      (infront of + there should be one space)
NAMES(CLUS1+                       (No Space in front of + from here onwards) 
,CLUS2+ 
,CLUS3+ 
,CLUS4+ 
,CLUS5)

---------- Post updated 03-21-14 at 04:49 AM ---------- Previous update was 03-20-14 at 05:08 AM ----------

I tried giving "|runmqsc -e $1" next to below lines but it is not executed.

Like below

1. }' add="$3"|runmqsc -e $1
2. exit
  }|runmqsc -e $1

3. print "alter",nl,s0|runmqsc -e $1
4. sub( /\)/, ","add"\)", s0)|runmqsc -e $1

i tried these above 4 steps individually but alter namelist command didn't execute

Hi,

Can you please let me know on executing the above command from script?

This is correct:

Because the shell should redirect the stdout from the screen to the runmqsc command.
Everything between the 'ticks'

nawk '
...
'

is an argument for nawk (and in awk syntax - not shell syntax).
You mean you want to put another DESCR command with the shell's $2 parameter?
Like the add="$3" (3rd shell parameter passed to the add awk variable),
we can pass the $2 to another awk variable.

...
echo 'dis nl('$NL') names ' | runmqsc $1 | nawk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
sub( /\)/, ","addname"\)", s0)
print "ALTER", nl, s0, "DESCR (", descr, ")"
  }
}' addname="$3" descr="$2" | runmqsc -e $1

Thanks.. It worked. Your help is much appreciated.
Good thing is you understood my techonlogy commands and output also

---------- Post updated at 08:48 AM ---------- Previous update was at 08:40 AM ----------

Below is the code which worked.

#!/bin/ksh
if [ $# != 3 ]
then
echo usage: alterNamelist.sh QMGR MQREQ NAME
fi

NL=`echo 'dis qmgr'|runmqsc $1|grep REPOSNL|sed 's/.*REPOSNL\(.*\).*/\1/' |cut -d'(' -f2|cut -d')' -f1`

echo 'define nl('$NL'_'$2') like('$NL')'|runmqsc -e $1

echo 'dis nl('$NL') names ' | runmqsc $1 | nawk '
$1~/^NAMELIST ?\(/ {nl=$0}
$1~/^NAMES ?\(/ {a=1}
a==1 {
  s0=s0 $0
  if (/\)/) {
sub( /\)/, ","add"\)", s0)
print "alter",nl,s0
    exit
  }
}' add="$3" descr="$2" | runmqsc -e $1


---------- Post updated at 09:07 AM ---------- Previous update was at 08:48 AM ----------

There is an issue came..
When i am doing for large no of clusters it is throwing error like below

alter     NAMELIST(NT.CL.HOME_NL_NAMES)             NAMES(CLUS1                                   ,CLUS2                                   ,CLUS3                                   ,CLUS4                                   ,CLUS21                                  ,CLUS31                                  ,CLUS41                                  ,CLUS22                                  ,CLUS32                                  ,CLUS42                                  ,CLUS23                                                                  ,CLUS322                                 ,CLUS422                                 ,CLUS212                                 ,CLUS3D12                                ,CLUS4D12                                ,CLUS2S22                                ,CLUS3DD2S2                              ,CLUS4S22                                ,CLUS2D32                                ,CLUS3S32                                ,CLUS432                                ,CLUS5
AMQ8427: Valid syntax for the MQSC command:

  ALTER NAMELIST( namelist_name )
   [ DESCR( string ) ]
   [ NAMES( string ) ]
One MQSC command read.
One command has a syntax error.

It is giving because when there are large no of (more than 1 line) then it throws syntax error. If it is altering like below then it will work.

ALTER NAMELIST(BT.CL.HOME_NL_NAMES) +
NAMES(CLUS1+
,CLUS2+
,CLUS3+
,CLUS4+
,CLUS21+
,CLUS31+
,CLUS41+
,CLUS22+
,CLUS32+
,CLUS42+
,CLUS23+
,CLUS33+
,CLUS43+
,CLUS222+
,CLUS322+
,CLUS422+
,CLUS212+
,CLUS312+
,CLUS412+
,CLUS222+
,CLUS322+
,CLUS422+
,CLUS232+
,CLUS332+
,CLUS3s32+
,CLUS432+
,CLUS5)

out put: of

 dis NAMELIST(NT.CL.HOME_NL_NAMES)

is below

dis NAMELIST(NT.CL.HOME_NL_NAMES)
AMQ8550: Display namelist details.
   NAMELIST(NT.CL.HOME_NL_NAMES)           NAMCOUNT(21)
   NAMES(CLUS1
        ,CLUS2
        ,CLUS3
        ,CLUS4
        ,CLUS21
        ,CLUS31
        ,CLUS41
        ,CLUS22
        ,CLUS32
        ,CLUS42
        ,CLUS23
        ,CLUS33
        ,CLUS43
        ,CLUS222
        ,CLUS322
        ,CLUS422
        ,CLUS212
        ,CLUS312
        ,CLUS412
        ,CLUS222
        ,CLUS5
        ,CL06)                             DESCR(MQ123)
   ALTDATE(2014-03-26)                     ALTTIME(13.37.48)