Tips on writing a script

When writing a script, it is often easier to define a set of variables at the beginning of the script. This makes any changes to the naming conventions or number of MQe objects easier to manage.

In TCL variables are defined using the set command and referenced using a $ in front of the variable name.

It is also useful to define variables in capital letters so that they can easily be identified within a script.
set PATH "C:\\MQeScript\\gateway"

When calling MQe_Script commands, they can be defined on their own or TCL control structures can be added to provide feedback on the success of the command and potentially exit the script if errors occur.

One method of checking the success of a command is to use an if / else block with a catch command.
if { [catch {mqe_script_qm -create -qmname $GATEWAYQM -qmpath
$PATH} error] } {
 		        puts "An error occurred creating queue manager"; 		
            puts "The reason was: $error"
 		        exit 
} else { 
      puts "Queue manager created"
}   

As the above code snippet shows, the puts command is used to print text to the screen and the exit command stops the execution of the script. If any errors are thrown, the error text is saved in the variable named “error” and can then be accessed.

If a script is being written to create a number of bridge objects defined by a variable, the creation of those objects can be placed inside a loop. The easiest method of creating multiple objects is to have a standard name for each of the objects then add a number to each of them so they are unique.
for {set j 1} {$j <= $QNUM} {incr j} {

  	   #create all the client connections

mqe_script_mqconn -create -clientconnname $CC$j -proxyname $PROXY -bridgename $BRIDGE -syncqname $SYNCQ$j -port $PORT

}   
The above snippet shows how names can be created using a loop variable. $CC is already defined as a client connection name prefix and $SYNCQ as a sync queue name prefix.

The code snippet also introduces the use of the # to define a comment.

In order to supply MQe_Script with a script file, it must be saved with a .tcl extension and the command to supply a script is the source command.
source {C:\MQeScript\gatewayscript.tcl}  
For more information on TCL and writing scripts, refer to the documentation accompanying MQe_Script.

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.