Shell scripting with passing arguments

Hi All,

I am using the script for creating local queue and passing the arguments while running the script as below

n=0
while [ $n -lt $1 ]
do
e=`expr $n + 3`
echo 'DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'' | /apps/mqm_opt/bin/runmqsc $2
n=`expr $n + 1`
done

Running the script

./sample.sh 3 QueueManager1 Q1 Q2 Q3 5000 4194304 NO

3 - Number of queues to be created
QueueManager1 - name of the queue manger
Q1 - Queue 1 to be created
Q2 - Queue 2 to be created
Q3 - Queue 3 to be created
5000 - Maxdepth of queue
4194304 - Size of message in queue
NO - Queue persistence
<null> - Cluster

In the above highlighted, the value should be either $3, $4, $5 based on the condition from "for loop" but the script takes the queue name as 3,4,5 instead of Q1,Q2,Q3 respectively.

I am not sure how the variable should be passed inside "DEFINE QL( )"

Can someone please help on this.

Thanks,
Anusha

You need to quote properly:

n=0
while [ $n -lt $1 ] do
  e=`expr $n + 3`
  echo "DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'" | /apps/mqm_opt/bin/runmqsc $2
  n=`expr $n + 1`
done

Hi,

I tried the same

echo "DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'" | /apps/mqm_opt/bin/runmqsc $2
./sample.sh 3 SDBXBRK2 Q1 Q2 Q3 5000 4194304 NO

Output is

"DEFINE QL('3') MAXDEPTH('5000') MAXMSGL('4194304') DEFPSIST('NO') ''
AMQ8405: Syntax error detected at or near end of command segment below

But the actual value should be
Q1 when n=0
Q2 when n=1
Q3 when n=3

Thanks,
Anusha

You can import any queue definition exported by simple runmqsc < inputfile (as you probably know)

Export a working QM in file using saveqmgr, or on newer MQ version dmpmqcfg .

Make a template out of it, by substituting values you wish (like names and port numbers) with shell variables ($PORT, $QDEPTH or alike)

Use that template for any new definition, parse the template and substitute variables with new required (best to source a file with all the variables exported, can be populated with shell script) and generate new file which you will use with runmqsc (leaving the template unchanged in the process).

This way you will have :
A configuration file for each new QMGR, with definitions and everything, per execution.
Validation of job done (a runmqsc file used will always be there)
Ease of future administration and code change (a introduction of new functionality required will be a new $VAR in template file and a new export $VAR in configuration file - minor changes)

Hope that helps
Regards
Peasant.

Ah, I see.

It is much easier to part the command line when the list of QLs is at the end of the argument list:

qm="${1}"
cluster="${2}"
maxdepth="${3}"
maxmsgl="${4}"
defpsist="${5}"

shift 5

for ql in "${@}"; do
  echo "DEFINE QL('$ql') MAXDEPTH('$maxdepth') MAXMSGL('$maxmsgl') DEFPSIST('$defpsist') '$cluster'" 
done \
| /apps/mqm_opt/bin/runmqsc $qm

The loop generates (replacing 'runmqsc' with 'cat'):

./mkql SDBXBRK2 '' 5000 4194304 NO Q1 Q2 Q3
DEFINE QL('Q1') MAXDEPTH('5000') MAXMSGL('4194304') DEFPSIST('NO') ''
DEFINE QL('Q2') MAXDEPTH('5000') MAXMSGL('4194304') DEFPSIST('NO') ''
DEFINE QL('Q3') MAXDEPTH('5000') MAXMSGL('4194304') DEFPSIST('NO') ''

Thank you!! It worked fine...

Thanks,
Anusha