#!/bin/ksh
#----------------------------------------------------------------------------#
#----- Create runstat ddl -----#
#----- Usage : crt_stat.ksh -----#
#----------------------------------------------------------------------------#
. $HOME/.profile
if [ $# -ne 2 ]; then
echo "Usage : $0 "
exit 1
fi
DBNM="$1"
SCHNM="$2"
DIR=`/usr/bin/dirname $0`
db2 connect to $DBNM
db2 "select 'db2 \"runstats on table ' ||rtrim(tabschema)||'.'||tabname|| ' and indexes all\"' from syscat.tables where type='T'" |
grep $SCHNM | cut -f 1-9 -d " " > $DIR/crt_stat.log
echo "EOF" >> $DIR/crt_stat.log
echo "#!/bin/ksh" > "$DIR"/"$DBNM"_runstats.ddl
echo ". $HOME/.profile" >> "$DIR"/"$DBNM"_runstats.ddl
echo "" >> "$DIR"/"$DBNM"_runstats.ddl
echo "db2 connect to $DBNM" >> "$DIR"/"$DBNM"_runstats.ddl
while read var1 var2 var3 var4 var5 var6 var7 var8
do
if [[ "$var1" = "EOF" ]]; then
break
fi
echo "echo \"$var5 -- start time: \`date +%H:%M\`"\" >> "$DIR"/"$DBNM"_runstats.ddl
echo "$var1 $var2 $var3 $var4 $var5 $var6 $var7 $var8" >> "$DIR"/"$DBNM"_runstats.ddl
echo "echo \"$var5 -- end time : \`date +%H:%M\`"\" >> "$DIR"/"$DBNM"_runstats.ddl
echo "echo \" \"" >> "$DIR"/"$DBNM"_runstats.ddl
echo "sleep 5" >> "$DIR"/"$DBNM"_runstats.ddl
done <$DIR/crt_stat.log
db2 connect reset
chmod 755 "$DIR"/"$DBNM"_runstats.ddl
==============================================================================
#!/bin/ksh
#----------------------------------------------------------------------------#
#----- Runstat on Database -----#
#----- Usage : runstat.ksh -----#
#----------------------------------------------------------------------------#
if [ $# -ne 3 ]; then
echo "Usage : $0 "
exit 1
fi
DBNM=$1
SCHNM=$2
LOG_DIR=$3
DIR=`/usr/bin/dirname $0`
export LOG=/"$LOG_DIR"/db/"$DBNM"_runstats.`date +%u`.log
exec >> $LOG 2>&1
$DIR/crt_stat.ksh $DBNM $SCHNM
$DIR/"$DBNM"_runstats.ddl
最终crontab -l 会显示如下:
00 01 * * * /home/db2inst1/runstats/runstat.ksh RORDB99 UATCFG /home/db2inst1/runstats/log
00 04 * * * /home/db2inst1/runstats/runstat.ksh RORDB99 UATATM /home/db2inst1/runstats/log
阅读(1883) | 评论(0) | 转发(0) |