mqsc_qmgrs script
mqsc_qmgrs is a Unix bash script that provides a way to call the client option of runmqsc for a group of queue managers and format the output into a file that contains all the raw output data and a file that has the individual results on one line (to aid with grep searches of the data). I am including the script at the bottom of this post as a reference.
There is more doc in the script itself on how to use it. Here is an example of some initial set up to be able to use the script on a RHEL7 server.
1) I have a RHEL7 server that has network connectivity to all of my queue manager servers and ports.
2) I installed a recent MQ Client version (e.g. 9.1.5.0) on the RHEL7 server. You need at least MQ v8 to have the runmqsc client capability.
3) I created a JSON ccdt for all of my queue managers and set up an ssl directory with a key.kdb configuration. I then set up the following environment variables:
export MQCHLLIB=/apps/mqtools
export MQCHLTAB=ccdt.json
export MQSSLKEYR=/apps/mqtools/ssl/key
4) In the mqsc-qmgrs script, I set up groups for my queue managers. For example, I have an ALL group that includes all the queue managers in my estate.
At this point I am all set to invoke the mqsc-qmgrs script. For example, on Linux I can run mqsc-qmgrs against all my queue managers in the ALL group to find cluster data for a certain queue TCZ.Q1:
1) I would edit a file called mqsc-qmgrs-TIMZ-input with the data "DIS QC(TCZ.Q1) ALL".
2) I would make sure my CCDT environment variables are all set (as was discussed above):
export MQCHLLIB=/apps/mqtools
export MQCHLTAB=ccdt.json
export MQSSLKEYR=/apps/mqtools/ssl/key
3) I would run the script as follows:
mqsc-qmgrs TIMZ ALL
4) The result would be the following two files:
# This file has all the resulting data for our mqsc command against all the queue managers in our ALL group
mqsc-qmgrs-TIMZ-output-all
# This file has the data above but formats it so that each unique result is on its own line (makes it easy to grep the data)
mqsc-qmgrs-TIMZ-output-all-1LS
mqsc_qmgrs script
#!/bin/bash
#
# NOTES:
# 1) mqsc-qmgrs requires an input of a queue manager group and a unique identifier text.
# A queue manager group contains a list of queue managers. The queue manager groups must also be defined near the top of the script.
# The unique identifier text allows multiple users to run mqsc-qmgrs in the same working directory. For this doc, we will assume TIMZ is used.
# Example: mqsc-qmgrs ALL TIMZ
#
# 2) mqsc-qmgrs must be executed in a directory that includes the file mqsc-qmgrs-TIMZ-input. This file will include the runmqsc commands to execute.
# Example: mqsc-qmgrs-TIMZ-input might include the following:
# DIS Q(*) ALL
# DIS QC(*) ALL
#
# 3) mqsc-qmgrs will produce many temporary output files that will start with mqsc-qmgrs-TIMZ-output* in the current working directory (CWD).
#
# 4) mqsc-qmgrs will produce a file in the CWD called mqsc-qmgrs-TIMZ-output-all, which includes all the runmqsc output from the queue manager group appended together.
#
# 5) mqsc-qmgrs will produce a file in the CWD called mqsc-qmgrs-TIMZ-output-all-1LS, which has the individual results put into one line. This 1LS file is helpful for doing greps.
# Example: If the following lines was returned in mqsc-qmgrs-TIMZ-output-all for queue manager QM1:
# AMQ8414: Display Channel details.
# CHANNEL(CL.2S.SERVER1) CHLTYPE(CLUSRCVR)
# ALTDATE(2016-03-11) ALTTIME(02.08.00)
# BATCHHB(1000) BATCHINT(0)
#
# then the following one line would appear in the mqsc-qmgrs-TIMZ-output-all-1LS file:
# QM1. AMQ8414: Display Channel details. CHANNEL(CL.2S.SERVER1) CHLTYPE(CLUSRCVR) ALTDATE(2016-03-11) ALTTIME(02.08.00) BATCHHB(1000)
#
# Define qmgr groups here
ALL="QM1 \
QM2 \
QM3 \
QM4 \
QM5 \
QM6"
TEST="QM1 \
QM2 \
QM3"
PROD="QM4 \
QM5 \
QM6"
# enforce a queue manager group is the first command line argument
if [ -z "$1" ];then
echo "Qmgr group argument 1 required!"
exit 1
fi
eval QMGR_GROUPS=\$$1
if [ A"$QMGR_GROUPS" = A ];then
echo "$1 is not a defined group!"
exit 1
fi
# enforce a unique identifier text for the second command line argument
if [ -z "$2" ];then
echo "Unique Identifier argument 2 required!"
exit 1
fi
if [ ! -f mqsc-qmgrs-$2-input ]; then
echo mqsc-qmgrs-$2-input must exist in current working directory!
exit 1
fi
PID=$$
rm mqsc-qmgrs-$2-output*
echo runmqsc commands that will be run against queue manager group $1 are:
cat mqsc-qmgrs-$2-input
# execute in parallel runmqsc -c against qmgrs in our qmgr group
echo Initiating runmqsc calls for queue managers in group $1
for QMGR in $QMGR_GROUPS
do
runmqsc -c $QMGR < mqsc-qmgrs-$2-input > mqsc-qmgrs-$2-output$QMGR$PID.txt &
WAIT_PIDS+=($!)
QMGR_HOLD+=($QMGR)
done
# wait for all runmqsc -c processes to finish, and store each process's exit code into array STATUS[].
for pid in ${WAIT_PIDS[@]}; do
wait ${pid}
STATUS+=($?)
done
# after all processes finish, check their exit codes in STATUS[].
# 0 (sunny day scenario) and 10 (objects not found) will be acceptable exit codes.
i=0
for st in ${STATUS[@]}; do
if [[ ${st} -ne 0 ]] && [[ ${st} -ne 10 ]]; then
echo "runmqsc -c for ${QMGR_HOLD[i]} failed! exiting!"
exit 1
fi
((i+=1))
done
# collect all the output from runmqsc -c into one file
echo Collect all runmqsc output into mqsc-qmgrs-$2-output-all
for QMGR in $QMGR_GROUPS
do
cat mqsc-qmgrs-$2-output$QMGR$PID.txt >> mqsc-qmgrs-$2-output-all
rm mqsc-qmgrs-$2-output$QMGR$PID.txt
done
# create another 1LS file that has all the individual results in one line records. This allows an easier way for users to grep results
echo Create another file mqsc-qmgrs-$2-output-all-1LS that has all the individual results in one line records
HoldTx="";QMGR="";
while read LineTx;
do
# We have encountered a new result. Print out what we had parsed for
# the previous result, a delimitter line, and then reset HoldTx
if [ A"${LineTx:0:3}" = AAMQ -o A"${LineTx:0:3}" = ACSQ ];then
echo "$QMGR $HoldTx";
for ((i=0;i<150;i++));
do
printf =;
done;
echo;
HoldTx="";
fi;
# We have encountered a new queue manager. Print out what we had parsed for
# the previous result, a delimitter line, and reset HoldTx, and grab new queue manager
if [ A"${LineTx:0:31}" = A"Starting MQSC for queue manager" ];then
echo "$QMGR $HoldTx";
for ((i=0;i<150;i++));
do
printf =;
done;
echo;
HoldTx="";
QMGR=${LineTx:32:48};
fi;
# store current line in our HoldTx variable
HoldTx=$HoldTx${LineTx:0:${#LineTx}}" ";
done < mqsc-qmgrs-$2-output-all > mqsc-qmgrs-$2-output-all-1LS; echo "$QMGR $HoldTx" >> mqsc-qmgrs-$2-output-all-1LS
echo Finished!