This is a small script changing the environmental settings based on the given instance name.

>>--- . dbtuswitch.sh ---+----------------+---+------------+---><
                         |                |   |            |
                         +--- INSTANCE ---+   +--- NODE ---+
                         |                |
                         +--- default ----+
                         |                |
                         +--- current ----+

Syntax diagram

Running multiple DB2 instances / nodes on a single machine, you will frequently switch between them. This is where this script comes into the game.

First of all it is important to call this script with the "." or source command, so it will be interpreted within the actual shell (therefore the x-attribute is not set, or allowed, for this script). Otherwise the shell calls a subshell, runs the script and returns (this results in a loss of the changes done to the environment). Please note, that you have to worry about this for the first call only (because the script creates an alias hiding the "dot-call").

Calling the script without any argument will get you a list of all available instances (except for the DB2 admin server instance). This list also contains information read from the configuration file [more].

Status    Name     Comment
--------- -------- --------------------------------------------------
<current> db2inst1 Productive Instance (default)
-         db2inst2 Test Instance

Sample output

The "Status" field remarks the current instance (reading the $DB2INSTANCE environment variable) and the default instance (reading the associated configuration file setting). Please note, that in a case where the current instance and the default instance are the same, only "<current>" is displayed.

Running the script with the keyword "default" changes the environment to the default instance - defined in the configuration file [more]. The keyword "current" indicates to stay by the current instance, in combination with a node number (NODE). This is useful to switch the DB2 node only. It is also possible to repair / refresh the environment.

Switching the DB2 instance to a given name (INSTANCE) or keyword, the following steps are performed by the script: