Created
May 28, 2013 16:13
-
-
Save angoca/5663946 to your computer and use it in GitHub Desktop.
Instance changer for a db2 server
When you have a DB2 server, with many instances, and you have to work in all of them from the same user, this is a useful script that allows you to switch effeiciently from one environment to the other. You just need to put the file in any directory of your server, configure the directories (Instance home and in…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ksh | |
# Changes the environment to the given instance. | |
# You need to 'source' this command in order to change the environement. | |
# To ease the process, you can create an alias per instance in the .profile. | |
# alias i1=". ~/chins db2inst1" | |
#set -x | |
# Nom de l'instance en minuscule | |
INSTANCE=$1 | |
# Checks if an instance name was given. | |
if [ -z ${INSTANCE} ]; then | |
echo "Instance not defined" | |
else | |
INST_VALID=`/opt/ibm/db2/9.7/bin/db2greg -dump | grep I, | grep ,${INSTANCE},` | |
#echo "val '$INST_VALID'" | |
# Checks if the instance exists in the server | |
if [ -z ${INST_VALID} ]; then | |
echo "Invalid instance" | |
else | |
PROFILE_DIR="/home/${INSTANCE}/sqllib/db2profile" | |
if [ -f ${PROFILE_DIR} ]; then | |
. ${PROFILE_DIR} | |
fi | |
# Disconnect any existing connection. | |
CONN=$(db2 connect | awk '/Local database alias/ {print $5}') | |
if [ ! -z ${CONN} ] ; then | |
echo "Disconnected from $CONN" | |
fi | |
# Terminates the previous db2bp (DB2 backend process) | |
db2 terminate > /dev/null | |
echo "Current instance $DB2INSTANCE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was the previous idea before db2env: https://gist.github.com/angoca/6279599