#!/bin/bash

# customize this
TS=TS1
USER=cgadm/cgadm
HOST=localhost

### end of customization ###

apptotal=0
appusage=0
systotal=0
sysusage=0
temptotal=0
tempusage=0
 
row=0
for l in `cgadm --user=$USER --server=$HOST --raw --cmd="list datafile for $TS"`
do
        # echo $row - $l
        if (( row > 0 ))
        then
           IFS=',' read -r -a farray <<< "$l"
           ftype=${farray[1]}
           ftotal=${farray[2]}
           fused=${farray[3]}
 
           if [ "$ftype" == "APP" ]
           then
               (( apptotal += ftotal ))
               (( appusage += fused ))
           fi
           if [ "$ftype" == "SYSFILE" ]
           then
               (( systotal += ftotal ))
               (( sysusage += fused ))
           fi
           if [ "$ftype" == "TEMPFILE" ]
           then
               (( temptotal += ftotal ))
               (( tempusage += fused ))
           fi
        fi
        ((row++))
done
 
# echo "App Total = $apptotal"
# echo "App Used = $appusage"
 
app=`bc <<< "scale=2; 100 * $appusage / $apptotal" | sed 's/^\./0./'`
sys=`bc <<< "scale=2; 100 * $sysusage / $systotal" | sed 's/^\./0./'`
temp=`bc <<< "scale=2; 100 * $tempusage / $temptotal" | sed 's/^\./0./'`
 
echo "Database Usage for tableset $TS"
echo "Sys Usage = $sys%"
echo "Temp Usage = $temp%"
echo "App Usage = $app%"
 