Shell script xmpDB2All.sh to execute commands at all DB2 instances
Do you need to execute one ore more commands at all of your DB2 instances? Then you should deploy xmpDB2all.sh!
This script …
- locates all DB2 instances using profiles.reg (DB2 9.1) or global.reg (9.7 or later)
- executes commands passed as arguments
#!/bin/ksh
################################################################################
# xmpDB2All.sh - DB2 Command an allen DB2 Instanzen eines Systems ausführen
# ------------------------------------------------------------------------------
# Parameter: db2cmd - DB2 Command (je Instanz)
# regfile - Pfad zu DB2 Instance Registry (optional)
#
# Calls ...: xmpLog.pl - Logs events
#
# Comment : Die Instanzen eines DB2 Systems sind unter Unix im Pfad /var/db2/vn
# gespeichert. Mit dem Namen kann dann die /etc/passwd nach Instance
# Home Directories durchsucht werden. Hier setzt man dann mit dem Cmd
# db2profile die Umgebung und kann dann beliebige DB2 Commands
# ausführen.
# Dieses Script eignet sich besonders für das Stoppen und Starten
# aller Instanzen auf einem System, wobei die Instanzen nicht
# bekannt sein müssen.
#
# ------------------------------------------------------------------------------
# Autor G.Ruban /18.09.00 - erste Version V1.1
# G.Ruban /20.02.01 - V1.2 Protokollierung per xmpLog.pl Perl Script
# G.Ruban /10.07.01 - V1.3 Perl Path (whence) in PATH setzen
# G.Ruban /13.01.03 - V1.4 Output überarbeitet
# G.Ruban /05.12.06 - V2.0: Some amendments necessary for DB2 V9.1
# G.Ruban /29.07.11 - V2.1: Some amendments necessary for DB2 V9.7,
# profiles.reg not longer supported,
# function library xmpFunktion.sh removed
################################################################################
#-------------------------------------------------------------------------------
# Init
#-------------------------------------------------------------------------------
PROG=`basename $0`
VER="2.1"
#-------------------------------------------------------------------------------
# Pfad der DBA's Administrationsfunktion, -steuerdaten festlegen
#-------------------------------------------------------------------------------
# der Defaultwert ist :
xmpDbaDir="/opt/xmpdba"
export xmpDbaDir
xmpDbaDir="$xmpDbaDir"
#-------------------------------------------------------------------------------
# Perl Library in der Umgebung gefunden? Wenn nicht, setzen!
#-------------------------------------------------------------------------------
if [ ! "$PERL5LIB" ]; then
PERL5LIB=":/usr/local/bin:$xmpDbaDir/bin"
export PERL5LIB
else
if [ -z `echo $PERL5LIB | grep "[.]*$xmpDbaDir/bin[.]*"` ]; then
PERL5LIB="$PERL5LIB:/usr/local/bin:$xmpDbaDir/bin"
export PERL5LIB
fi
fi
#-------------------------------------------------------------------------------
# Determine db2ls command to inquire installed software
#-------------------------------------------------------------------------------
db2lspath=`which db2ls`
rc=$?
if [ $rc -ne 0 ] ; then
echo ">>> $PROG: DB2 Utility db2ls not found in current path."
db2lspath="/usr/local/bin/db2ls"
echo ">>> Execution path set to $db2lspath."
fi
#-------------------------------------------------------------------------------
# Inquire latest installation path of DB2 (provides 1 item)
#-------------------------------------------------------------------------------
db2sw=`$db2lspath | grep db2 | awk '{print $1}' | tail -1`
rc=$?
if [ $rc -ne 0 ] ; then
echo "Neither DB2 V9.7 nor V9.1 found, continue searching older versions ..."
echo "abends with RC=16"
exit 16
fi
if [ ! "$db2sw" ]; then
echo "$0: DB2 command db2ls found but no installed DB2 products found!"
echo "abends with RC=16"
exit 16
fi
#-------------------------------------------------------------------------------
# For archive reasons only: Determination of profiles.reg and global.reg
# < V9.1: /tmp/profiles.reg
# = V9.1: /opt/IBM/db2/V9.1/profiles.reg
# = V9.7: /var/[opt/]db2/global.reg
# regfile=`find /var/db2/ -name 'global.reg' -type f -print;find /var/opt/db2/ -name 'global.reg' -type f -print;find /var/db2/ -name 'profiles.reg' -type f -print;find $db2ip -name 'profiles.reg' -type f -print`
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Inquire all instances from DB2 registry, list instance name and path only
#-------------------------------------------------------------------------------
db2greg=$db2sw"/bin/db2greg -dump"
echo ">>> $db2greg"
ilist=`$db2greg | awk -F, '/I,DB2/ {print $4":"$5}'`
echo ">>> $ilist"
#-------------------------------------------------------------------------------
# Info Block ausgeben
#-------------------------------------------------------------------------------
echo $PROG " - V$VER"
echo "======================================================="
echo "Current User ................: "`id`
echo "Current Date/Time ...........: "`date +%Y-%m-%d-%H.%M.%S`
echo "System ......................: "`uname -n`
echo "DB2 Command .................: $1"
#-------------------------------------------------------------------------------
# Argumente Prüfen
#-------------------------------------------------------------------------------
if [ $# -lt 1 or $1 = ? ] ; then
echo "Syntax für $0 db2cmd regfile"
echo "... where db2cmd = DB2 Command, e.g. db2stop"
echo "Abend mit RC=4"
exit 4
fi
#-------------------------------------------------------------------------------
# Perl Bin Path in PATH setzen
#-------------------------------------------------------------------------------
perlpath=`whence perl`
if [ $? -ne 0 ] ; then
if [ -x "/usr/local/bin/perl" ]; then
PATH="$PATH:/usr/local/bin"
export PATH
else
if [ -x "/usr/bin/perl" ]; then
PATH="$PATH:/usr/bin"
export PATH
else
echo "$0: Perl Binary not found, possibly cannot execute Perl."
fi
fi
else
perlpath=`dirname $perlpath`
PATH="$PATH:$perlpath"
export PATH
fi
# echo "PATH=$PATH"
#-------------------------------------------------------------------------------
# Liste der Instanzen aus profiles.reg abarbeiten
#-------------------------------------------------------------------------------
maxrc=0
for i in $ilist
do
#---------------------------------------------------------------------------
# split instance name and instance path
#---------------------------------------------------------------------------
instname=${i%:*}
instpath=${i#*:}
#echo ">>>instname=$instname instpath=$instpath"
#---------------------------------------------------------------------------
# Prüfen, ob db2profile Script vorhanden ist
#---------------------------------------------------------------------------
echo "--------------------------------------------------------------------------------"
if [ -x "$instpath/db2profile" ]; then
echo "- Instance ..................: $instname"
echo " - Home Directory ..........: $instpath"
out=`ksh -c ". $instpath/db2profile; $1; exit"`
rc=$?
echo " - Requested Command - RC ..: $rc"
echo " - Command Output ..........: $out"
if [ $rc -gt maxrc ]; then
maxrc=$rc
fi
#---------------------------------------
# Protokollierung
#---------------------------------------
perl ${xmpDbaDir}/bin/xmpLog.pl -a "xmpDB2All.sh" -s "I" -t "RC=$rc CMD=$1"
else
echo "- Instance ..................: $instname"
echo " - Home Directory ..........: $instpath"
echo " Warning! IBM-supplied script 'db2profile' not found in DB2 path."
rc=4
if [ $rc -gt maxrc ]; then
maxrc=$rc
fi
fi
done
#-------------------------------------------------------------------------------
# *** ENDE ***
#-------------------------------------------------------------------------------
if [ $maxrc -ne 0 ]; then
WarningMsg "$0 finished. (RC=$maxrc)"
else
echo "$0 finished. (RC=$maxrc)"
fi
perl ${xmpDbaDir}/bin/xmpLog.pl -a "xmpDB2All.sh" -s "I" -t "MAXRC=$maxrc"
exit $maxrc
(Some comments are in german language. If you need assistence, please contact!)
This script may helps administrators to …
- first stop all application services
- then stop all DB2 instances
- to do their maintenance, e.g. full system backups, hardware or software maintenance
- use it in rc2.d to start/stop DB2, so help starting/stopping a server







Comments
Comments are closed.