IBM MQ is a robust product and queue managers can run without problems for months, or even years at a time. In fact, often when problems do occur they are the result of human error, and one example of such as error can be running an MQSC script against an unintended queue manager.
I think we have all pushed an MQSC file into the wrong queue manager. 😦
So, the question was asked, how can I ensure that I only run my MQSC script against the queue manager it was intended for?
This is something that MQSCX can help you with. There are a few ways you can do this.
Check that you are connected to the correct queue manager
One way to protect against running an MQSC script against the wrong queue manager is to start the script with a quick test to see which queue manager it is currently connected to and to exit the script immediately if it is found to be administering the wrong one.
if ( _qmgr != "QM1" ) print "Wrong queue manager! Script expects to be used on QM1" leave endif
_qmgr is an MQSCX system variable that tells you which queue manager you are administering. There are also some others that might be helpful when coding up checks at the start of a script, _connqmgr tells you which queue manager you are connected to, and will be different from _qmgr if you are using a via connection. _client tells you if you are connected as a client. You can see these in action in the DISPLAY DQM for Distributed blog post.
You could also make the check broader and have it query some attribute of the queue manager to determine if it was an appropriate queue manager to run the script against. For example, looking for the word “(Test)” in the queue manager description. This means a script couldn’t accidentally be run against one of your production queue managers. Using this simple technique, each script can be limited to a class of queue managers; Production, Test, Devt and so on.
DISPLAY QMGR DESCR if (!findstr("(Test)",DESCR)) print "Queue Manager",_qmgr,"does not appear to be a test QMgr" print "Queue Manager",_qmgr,"DESCR(",:n:DESCR,:n:")" leave endif
Have the script connect to the appropriate queue manager
As an alternative, rather than having the script check that the human running it has used the correct queue manager, the script could make the connection itself.
=conn qm(QM1) if (_lastrc) leave endif ALTER QMGR ... DEFINE CHANNEL ...
A script with commands for different queue managers
Having made a script that connects to the correct queue manager before running the commands against it, it is not difficult to make the next step where you can have a script that issues commands on multiple queue managers – has a section for each queue manager prefixed by an =conn command.
=conn qm(QM1) ALTER QMGR ... ALTER CHANNEL ... =conn qm(QM2) ALTER QMGR ... ALTER QLOCAL ... =conn qm(Q3) ALTER QLOCAL ...
This is only scratching the surface of what MQSCX can do, but it can certainly make administration of your IBM MQ queue managers less error prone.
If you’re not a current MQSCX licence holder, and you’d like to try out MQSCX, please email email@example.com to request a trial licence.
I was prompted to write this post as a result of this list-server question.