#!/bin/ksh

# populate_snapshot_tables.ksh - update snapshot tables from DB2
# snapshot administrative views
# designed to run via cron
# Last updated 2008.05.05
# Parameter:
# -d - Database name

USAGE="populate_snapshot_tables.ksh -d <database name> "
DB2PROF=/home/db2/sqllib/db2profile

if [ -f $DB2PROF ]; then
   . $DB2PROF
else
   echo "Cannot locate db2profile."
   echo "Looking for: $DB2PROF"
   USAGE
   exit 1
fi

while getopts  d: OPT
do
   case $OPT in
      d) database=$OPTARG ;;
      *) echo $USAGE; exit 1 ;;
   esac
done

if [[ "$database" = "" ]]; then
   echo $USAGE
   exit 1
fi

db2 connect to $database > /dev/null

db2 -x "insert into dba.snapdb select * from sysibmadm.snapdb" > /dev/null
db2 -x "insert into DBA.SNAPAPPL select * from sysibmadm.SNAPAPPL" > /dev/null
db2 -x "insert into DBA.SNAPSTMT select * from sysibmadm.SNAPSTMT where stmt_text is not null" > /dev/null
db2 -x "insert into DBA.SNAPTAB select * from sysibmadm.SNAPTAB " > /dev/null

db2 connect reset > /dev/null
db2 terminate > /dev/null
