#!/bin/ksh

SAMPLE_TIME=300
#SAMPLE_TIME=10

while true
do
   iostat ${SAMPLE_TIME} 2 > /tmp/msg$$
   COUNT=`cat /tmp/msg$$|wc -l `
   COUNT2=`expr $COUNT / 2`

   # This script is intended to run starting at 7:00 AM EST Until midnight EST
   cat /tmp/msg$$|sed 1,${COUNT2}d | awk  '{ printf("%s %s %s\n", $1, $5, $6) }W
   do
      if (echo $HDISK|grep -cq hdisk );then

      YEAR=`date +"%Y"`
      MONTH=`date +"%m"`
      DAY=`date +"%d"`
      HOUR=`date +"%H"`
      MINUTE=`date +"%M"`

      sqlplus -s / <<EOF
      insert into sys.iostat@sa9
                           values (sysdate, 
                           --$YEAR,$MONTH,$DAY,$HOUR,$MINUTE,
                           $SAMPLE_TIME, '$HDISK', $VMSTAT_IO_R,$VMSTAT_IO_W); 

      EXIT
EOF
      fi
   done
   rm /tmp/msg$$

   sqlplus -s / <<EOF

   insert into sys.sum_iostat@sa9 (
   select
      to_date(to_char(samp_date,'YYYY-MM-DD-HH-MI'),'YYYY-MM-DD-HH-MI') ,
      mount_point    ,
      $SAMPLE_TIME,
      sum(kb_read)   ,
      sum(kb_write)
   from
      sys.vol_grp a,
      sys.iostat b
   where
      a.hdisk = b.hdisk
   and
   to_char(samp_date,'YYYY-MM-DD-HH-MI') in
   (select max(to_char(samp_date,'YYYY-MM-DD-HH-MI')) from sys.iostat)
   group by
      to_date(to_char(samp_date,'YYYY-MM-DD-HH-MI'),'YYYY-MM-DD-HH-MI') ,
      mount_point
   );

   EXIT
EOF
