#!/bin/ksh
###############################################################################################################
###############################################################################################################
export LANG=en_US
osbox=`uname`
HOSTNAME=$(hostname)
INSTNAME=`ps -ef|grep db2sysc|grep -v grep |awk '{print $1}'|head -1`
createCheckDir(){
if [[ ! -d /tmp/db2check ]];then
mkdir -p /tmp/db2check
chmod 777 /tmp/db2check
fi
}
getInstance(){
if [[ "$INSTNAME" == "" ]];then
echo 1
exit 1
else
DB2LEVEL=`su - $INSTNAME -c "db2level" |grep tokens|awk -F'"' '{print $2}'|awk -F'v' '{print $2}'`
fi
}
getOSArchitecture(){
if [[ "${osbox}" == "Linux" ]];then
continue
elif [[ "${osbox}" == "AIX" ]];then
continue
else
echo "Current OS is ${osbox},not support."
exit 1
fi
}
get_table_count(){
instgroup=`id $1 | awk {'print $2'} | awk -F '=' {'print $2'} | awk -F '(' {'print $2'} | awk -F ')' {'print $1'}`
if [[ ! -f "/tmp/db2check/db2HistoryFilePath_tmp.file" ]];then
touch /tmp/db2check/db2HistoryFilePath_tmp.file
fi
chown $1:$instgroup /tmp/db2check/db2HistoryFilePath_tmp.file
chmod u+x /tmp/db2check/db2HistoryFilePath_tmp.file
echo "db2 -x /"connect to $2/" > /dev/null" > /tmp/db2check/db2HistoryFilePath_tmp.file
# echo "db2 -x /"select strip(tabschema) || '.' || strip(tabname) from SYSCAT.tables where tabschema NOT LIKE 'SYS%' and tabname not like 'EXPLAIN%' and tabname not like 'ADVISE%' and tabname not like 'IBMQ%' and TYPE='T'/"" >> /tmp/db2check/db2HistoryFilePath_tmp.file
echo "db2 -x /"select 'select ''' || strip(tabschema) || '.' || strip(tabname) || ''' , count(*) from '|| strip(tabschema) || '.' || strip(tabname) || ';' from SYSCAT.tables where type in ('T') AND tabschema NOT LIKE 'SYS%' and tabname not like 'EXPLAIN%' and tabname not like 'ADVISE%' and tabname not like 'IBMQ%'/"" >> /tmp/db2check/db2HistoryFilePath_tmp.file
echo "db2 terminate > /dev/null" >> /tmp/db2check/db2HistoryFilePath_tmp.file
echo "connect to $2;" > /tmp/db2check/${inst}_${dbname}.out
su - $1 -c "/tmp/db2check/db2HistoryFilePath_tmp.file" >> /tmp/db2check/${inst}_${dbname}.out
echo "terminate;" >> /tmp/db2check/${inst}_${dbname}.out
chown $1:$instgroup /tmp/db2check/${inst}_${dbname}.out
chmod +x /tmp/db2check/${inst}_${dbname}.out
su - $1 -c "db2 -txf /tmp/db2check/${inst}_${dbname}.out" >> /tmp/db2check/${inst}_${dbname}.res
}
getDb2Level(){
if [[ $DB2LEVEL == 11.1* ]];then
continue
else
echo "Current DB2 VERSION will not test."
exit 1
fi
}
getIndirectDBnames(){
if [[ "$osbox" == "Linux" ]];then
dblist=`su - $1 -c "db2 list db directory | grep -B5 Indirect | grep 'Database name'" | grep -v 'YOU HAVE NEW MAIL' | awk '{print $4}' | uniq`
elif [[ "$osbox" == "AIX" ]];then
dblist=`su - $1 -c "db2 list db directory" | awk '{a[NR]=$0}END{for (i=1;i<=NR;i++) if (a[i]~/Indirect/) for (j=i-5;j<i;j++) print a[j]}' | grep 'Database name' | grep -v 'YOU HAVE NEW MAIL' | awk '{print $4}' | uniq`
else
exit 1
fi
}
main(){
getOSArchitecture
getInstance
createCheckDir
getDb2Level
for inst in `ps -ef | grep db2sysc | grep -v grep | awk '{print $1}' |uniq`;do
getIndirectDBnames $inst
for dbname in `echo $dblist`;do
get_table_count $inst $dbname
done
done
}
main
版权声明:本文为博主原创文章,未经博主允许不得转载。
DB2
- 上一篇:windows查看文件修改
- 下一篇:MSSQL常用SQL