if [[ $(dspmq | grep '(Running)' | grep "$QMgr" | wc -l | tr -d " ") != 1 ]]
The above code is to check if queue manager is running or not.
Is there any command to check whether the given queue name is exists in the queue manager or not?
Adding another suggestion in addition to what Rob and T.Rob have said.
MQ v7.1 and higher come with the dmpmqcfg command and you can use this to check for a specific queue.
The examples below are in line with your sample that checks if a queue manager is running:
To use dmpmqcfg to check if a queue name of any type exists you could do this:
if dmpmqcfg -m ${QMgr} -t queue -x object -o 1line -n ${QName}|egrep '^DEFINE '; then
echo "Queue ${QName} exists on Queue Manager ${QMgr}
fi
Using the method Rob Parker provided* to check if a queue name of any type exists:
*Note I used DISPLAY Q(
instead of DISPLAY QLOCAL(
if printf "DISPLAY Q(${QName})" | runmqsc ${QMgr} 2>&1 >/dev/null; then
echo "Queue ${QName} exists on Queue Manager ${QMgr}
fi
Your example check for a queue manager Running could be simplified to this:
if dspmq -m ${QMgr}| grep --quiet '(Running)'; then
echo "Queue Manager ${QMgr} is Running"
fi
There's not a specific command but you could use:
printf "DISPLAY QLOCAL(<QUEUE NAME>)" | runmqsc <QM Name>
You will get a Return Code of 10 if it does not exist and 0 if it does. One thing to note, the Queue Manager must be running and you must run the command as someone who has access to the Queue Manager in question otherwise you'll get different return codes! (20 for Queue Manager not running and not authorized)
Given you haven't specified a specific Queue type i've assumed you're looking for QLocal's but you could search on any Queue Type by modifying the above command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With