Document Type | Technical Information
Category | Utility
Applicable Product Versions | Tibero5/Tibero6/Tibero7
Document Number | TUTTI030
Overview
This document explains how to use the Shell environment configuration utility designed to simplify the use of multi-instances when internal testing of Tibero or operation of multiple binaries is required.
Method
1. Create Shell
#!/bin/sh
#########################################
# @File name : tbenv #
# @Created by : Bach #
# @Created date : 2013.08.19 #
# @Team : 001 team #
# @EX : $ . tbenv #
# @Modifed History #
# version : name / team : date #
# ------------------------------------- #
# ver1.00 : Bach / 001 : 20130819 #
# ver1.10 : Bach / 001 : 20131213 #
# ver1.11 : Bach / 001 : 20140109 #
# ver1.12 : Bach / 001 : 20140219 #
# ver1.13 : Bach / 001 : 20140325 #
# ver1.20 : Bach / 002 : 20151228 #
# ver1.21 : Bach / 002 : 20181204 #
#########################################
####################
# Variable Setting #
####################
unset OLDSID OLDHOME NEWSID NEWHOME TBHOME TBSID sid sidmax tbhome chk check i j k l m n o yn
### Environment variable for echo options by UNIX type
N=
C=
if echo "\c" | grep c >/dev/null 2>&1; then
N='-n'
else
C='\c'
fi
OS=`uname`
### Store existing TB_SID environment variable
case "${TB_SID}" in
"") OLDSID=$LOGNAME ;;
*) OLDSID=$TB_SID ;;
esac
### Store existing TB_HOME variable
#if [ -z "${TB_HOME}" ]; then
# OLDHOME=$PWD
#else
# OLDHOME=$TB_HOME
#fi
# Modified on 2018.12.04
#OLDHOME=$TB_HOME
OLDHOME=${TB_HOME:-$HOME}
##########################
# Definition of Function #
##########################
function FUNC_no_tbtab
{
echo $N "TB_SID = [$OLDSID] ? $C"
read NEWSID
case "${NEWSID}" in
"") TB_SID="$OLDSID" ;;
*) TB_SID="$NEWSID" ;;
esac
export TB_SID
# Modified on 2018.12.04
#if [ -z "${OLDHOME}" ]; then
# echo $N "TB_HOME = [$HOME] ? $C"
#else
# echo $N "TB_HOME = [$OLDHOME] ? $C"
#fi
echo $N "TB_HOME = [$OLDHOME] ? $C"
read NEWHOME
case "$NEWHOME" in
"") TB_HOME=$OLDHOME ;;
*) TB_HOME=$NEWHOME ;;
esac
export TB_HOME
}
function FUNC_sid_home_list ### Output list of SID and HOME Path from "$HOME/.tbtab"
{
clear
printf "%-20s %s \n" "Tibero SID" "Tibero Home Path"
echo "---------------------------------------------------------------------------------"
### Declare variables for array use
i=0
j=0
for sid in `cut -d":" -f1 $HOME/.tbtab | sort -u`
do
k=0
let i=i+1
let j=i*100
TBSID[$i]=$sid
printf "%-20s " "[$i] ${TBSID[$i]}"
for tbhome in `grep -w "^${TBSID[$i]}:" $HOME/.tbtab 2>/dev/null | cut -d":" -f2`
do
let j=j+1
let k=k+1
TBHOME[$j]=$tbhome
printf "%s \n %-20s " "[$k] ${TBHOME[$j]}"
done
printf "\n"
done
echo "---------------------------------------------------------------------------------"
sidmax=${i}
}
function FUNC_sid_home ### Function to set SID and HOME
{
while true ### SID input
do
if [ ${sidmax} -le 1 ] ### If existing SIDs are one or less
then
echo $N "Insert TB_SID = [$OLDSID] ? $C"
else
echo $N "Select [1 ~ $sidmax] or Insert TB_SID = [$OLDSID] ? $C"
fi
read NEWSID
case "${NEWSID}" in
[1-9]|[1-9][0-9]) if [ -z "${TBSID[$NEWSID]}" ] ### Select SID matching the number in the list
then
printf "\n %s\n \n" "**** Out of range ****"
continue
else
export TB_SID=${TBSID[$NEWSID]}
FUNC_num_home
break
fi ;;
"") TB_SID=$OLDSID ### Use existing SID if no input
FUNC_nm_home
break ;;
*) TB_SID=$NEWSID ### Use new value as SID
FUNC_nm_home
break ;;
esac
done
export TB_SID TB_HOME
}
function FUNC_num_home ### Set home path when NEWSID value is numeric
{
### Declare variables (l: count of home paths, m: array index of TBHOME variable)
l=0
m=0
let m=NEWSID*100
while true ### Check number of HOME paths per SID
do
let m=m+1
if [ -z "${TBHOME[$m]}" ]
then
break
fi
let l=l+1
done
while true
do
if [ ${l} -le 1 ]
then
let n=NEWSID*100+1
DFTHOME=${TBHOME[$n]:-$PWD}
echo $N "TB_HOME = [$DFTHOME] ? $C"
else
echo $N "Select [1 ~ $l] or Insert TB_HOME = ? $C"
fi
read NEWHOME
case "${NEWHOME}" in
[1-9]|1[0-9]) let n=NEWSID*100+NEWHOME
if [ -z "${TBHOME[$n]}" ]
then
printf "\n %s\n \n" "**** Out of range ****"
continue
else
TB_HOME=${TBHOME[$n]}
break
fi ;;
"") if [ ${l} -le 1 ]
then
TB_HOME=$DFTHOME
break
fi
continue ;;
*) TB_HOME=$NEWHOME
break ;;
esac
done
}
function FUNC_nm_home ### Set home path when NEWSID value is a string
{
o=0
while [ ${o} -le ${sidmax} ] ### Check if matches existing SID
do
let o=o+1
if [ "${TB_SID}" == "${TBSID[$o]}" ] ### If matches existing SID, return array number and run FUNC_num_home
then
unset NEWSID
NEWSID=$o
FUNC_num_home
break
fi
done
if [ ${o} -gt ${sidmax} ] ### If new SID, set new home path
then
echo $N "TB_HOME = [$OLDHOME] ? $C"
read NEWHOME
while true
do
case "$NEWHOME" in
"") if [ -z "${OLDHOME}" ]
then
continue
else
TB_HOME=$OLDHOME
break
fi ;;
*) TB_HOME=$NEWHOME
break ;;
esac
done
fi
}
function FUNC_tbtab ### Check if SID and HOME info exist in "$HOME/.tbtab" file
{
for chk in `grep -w "^$TB_SID:$TB_HOME:N" $HOME/.tbtab 2>/dev/null`
do
check=${chk}
done
if [ -z "${check}" ]
then
echo $N "Insert \"$TB_SID:$TB_HOME\" $HOME/.tbtab ?(Y/N): $C"
read yn
case $yn in
Y|y) echo "$TB_SID:$TB_HOME:N" >> $HOME/.tbtab ;;
N|n) ;;
*) FUNC_tbtab ;;
esac
fi
}
function FUNC_lib ### Modify Library path
{
if [ "$OS" == "Linux" ] || [ "$OS" == "SunOS" ]
then
case ${LD_LIBRARY_PATH:-""} in
*$OLDHOME/lib*$OLDHOME/client/lib*)
LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$OLDHOME/client/lib*$OLDHOME/lib*)
LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$TB_HOME/lib*) ;;
"") LD_LIBRARY_PATH=$TB_HOME/lib:$TB_HOME/client/lib:$LD_LIBRARY_PATH ;;
*) LD_LIBRARY_PATH=$TB_HOME/lib:$TB_HOME/client/lib:$LD_LIBRARY_PATH ;;
esac
export LD_LIBRARY_PATH
elif [ "$OS" == "HP-UX" ]
then
case ${SHLIB_PATH:-""} in
*$OLDHOME/lib*$OLDHOME/client/lib*)
SHLIB_PATH=`echo $SHLIB_PATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$OLDHOME/client/lib*$OLDHOME/lib*)
SHLIB_PATH=`echo $SHLIB_PATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$TB_HOME/lib*) ;;
"") SHLIB_PATH=$TB_HOME/lib:$TB_HOME/client/lib:$SHLIB_PATH ;;
*) SHLIB_PATH=$TB_HOME/lib:$TB_HOME/client/lib:$SHLIB_PATH ;;
esac
export SHLIB_PATH
elif [ "$OS" == "AIX" ]
then
case ${LIBPATH:-""} in
*$OLDHOME/lib*$OLDHOME/client/lib*)
LIBPATH=`echo $LIBPATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$OLDHOME/client/lib*$OLDHOME/lib*)
LIBPATH=`echo $LIBPATH | \
sed "s;$OLDHOME/lib;$TB_HOME/lib;g" | \
sed "s;$OLDHOME/client/lib;$TB_HOME/client/lib;g"` ;;
*$TB_HOME/lib*) ;;
"") LIBPATH=$TB_HOME/lib:$TB_HOME/client/lib:$LIBPATH ;;
*) LIBPATH=$TB_HOME/lib:$TB_HOME/client/lib:$LIBPATH ;;
esac
export LIBPATH
fi
if [ -z "${LD_LIBRARY_PATH}" -a -z "${LIBPATH}" ]
then
LIBPATH=$TB_HOME/lib:$TB_HOME/client/lib
LD_LIBRARY_PATH=${LIBPATH}
export LD_LIBRARY_PATH LIBPATH
fi
}
function FUNC_path ### Modify PATH variable
{
case "${PATH}" in
*$OLDHOME/bin*$OLDHOME/client/bin*) PATH=`echo $PATH | \
sed "s;$OLDHOME/bin;$TB_HOME/bin;g" | \
sed "s;$OLDHOME/client/bin;$TB_HOME/client/bin;g"` ;;
*$OLDHOME/client/bin*$OLDHOME/bin*) PATH=`echo $PATH | \
sed "s;$OLDHOME/bin;$TB_HOME/bin;g" | \
sed "s;$OLDHOME/client/bin;$TB_HOME/client/bin;g"` ;;
*$TB_HOME/bin*) ;;
*:) PATH=${PATH}:$TB_HOME/bin:$TB_HOME/client/bin: ;;
"") PATH=$TB_HOME/bin:$TB_HOME/client/bin ;;
*) PATH=$PATH:$TB_HOME/bin:$TB_HOME/client/bin ;;
esac
export PATH
}
function FUNC_prof ### Modify TB_PROF_DIR path TB_PROF_DIR=$TB_HOME/bin/prof
{
case "${TB_PROF_DIR}" in
*$OLDHOME/bin/prof*) TB_PROF_DIR=`echo $TB_PROF_DIR | \
sed "s;$OLDHOME/bin/prof;$TB_HOME/bin/prof;g"` ;;
*$TB_HOME/bin/prof*) ;;
*) TB_PROF_DIR=$TB_HOME/bin/prof ;;
esac
export PATH
}
################
# Excute Shell #
################
if [ -f $HOME/.tbtab ]
then
FUNC_sid_home_list
FUNC_sid_home
else
FUNC_no_tbtab
fi
FUNC_tbtab
FUNC_lib
FUNC_path
FUNC_prof
printf "%s\n%s\n" "TB_SID = $TB_SID" "TB_HOME = $TB_HOME"
unset FUNC_lib FUNC_nm_home FUNC_no_tbtab FUNC_num_home FUNC_path FUNC_prof FUNC_sid_home FUNC_sid_home_list FUNC_tbtab
unset OLDSID OLDHOME NEWSID NEWHOME TBHOME TBSID sid sidmax tbhome chk check i j k l m n o yn OS
#################
# Alias Setting #
#################
alias tbhome='cd $TB_HOME'
alias tbbin='cd $TB_HOME/bin'
alias tblog='cd $TB_HOME/instance/$TB_SID/log'
alias tbcfg='cd $TB_HOME/config'
alias tbcfgv='vi $TB_HOME/config/$TB_SID.tip'
#alias tbdata='cd $TB_HOME/tbdata'
alias tbi='cd $HOME/tbinary'
#alias clean='tbdown clean'
alias dba='tbsql sys/tibero'
alias tm='$HOME/tbinary/monitor/monitor'
alias tbcli='cd ${TB_HOME}/client/config'
alias tbcliv='vi ${TB_HOME}/client/config/tbdsn.tbr'
#alias tbcliv='vi ${TB_HOME}/client/config/tbnet_alias.tbr'
2. First Use
$ source ./tbenv
TB_SID = [tb7] ? #### The value inside [] is the default OS account, enter desired TB_SID
TB_HOME = [/tibero7/tibero7] ? #### Enter the binary path to use
Insert "tb7:/tibero7/tibero7" /tibero7/.tbtab ?(Y/N): Y #### Enter Y to permanently save this information, otherwise N
TB_SID = tb7 #### Configured TB_SID information
TB_HOME = /tibero7/tibero7 #### Configured TB_HOME information
$ echo $TB_SID
tb7
$ echo $TB_HOME
/tibero7/tibero7
3. Reuse
$ source ./tbenv
Tibero SID Tibero Home Path
---------------------------------------------------------------------------------
[1] tb7 [1] /tibero7/tibero7
---------------------------------------------------------------------------------
Insert TB_SID = [tb7] ? 1 #### Enter the TB_SID to use, numeric input allowed, addition possible
TB_HOME = [/tibero7/tibero7] ? 1 #### Enter the TB_HOME to use, numeric input allowed, addition possible
TB_SID = tb7
TB_HOME = /tibero7/tibero74. Add Instance
$ source ./tbenv
Tibero SID Tibero Home Path
---------------------------------------------------------------------------------
[1] tb7 [1] /tibero7/tibero7
---------------------------------------------------------------------------------
Insert TB_SID = [tb7] ? test
TB_HOME = [/tibero7/tibero7] ? /tibero7/tibero7
Insert "test:/tibero7/tibero7" /tibero7/.tbtab ?(Y/N): Y
TB_SID = test
TB_HOME = /tibero7/tibero7
5. Add Engine
$ source ./tbenv
Tibero SID Tibero Home Path
---------------------------------------------------------------------------------
[1] tb7 [1] /tibero7/tibero7
[2] test [1] /tibero7/tibero7
---------------------------------------------------------------------------------
Select [1 ~ 2] or Insert TB_SID = [test] ? 2
TB_HOME = [/tibero7/tibero7] ? /home/tibero/tibero7
Insert "test:/home/tibero/tibero7" /tibero7/.tbtab ?(Y/N): Y
TB_SID = test
TB_HOME = /home/tibero/tibero7
$ source ./tbenv
Tibero SID Tibero Home Path
---------------------------------------------------------------------------------
[1] tb7 [1] /tibero7/tibero7
[2] test [1] /tibero7/tibero7
[2] /home/tibero/tibero7
---------------------------------------------------------------------------------
Select [1 ~ 2] or Insert TB_SID = [test] ?