#!/bin/ksh
#set -x
typeset -i CapT3=0
typeset -i CapT4=0
typeset -i NumT3=0
typeset -i NumT4=0
typeset -i NumMeta=0
typeset -i b=0

repdir=/export/home/san/capacity/reports
tmpdir=/export/home/san/capacity/tmp
export tmpdir repdir
outfile=${repdir}/FDC_symm_cap_report.txt


# Create tempfiles
pbrun symmaskdb -sid 3544 list no_assignment | sort -u | grep -v Symmetrix | grep -v Director | grep -v assigned > ${tmpdir}/3544_noassign.txt
pbrun symmaskdb -sid 3810 list no_assignment | sort -u | grep -v Symmetrix | grep -v Director | grep -v assigned > ${tmpdir}/3810_noassign.txt
pbrun symmaskdb -sid 3564 list no_assignment | sort -u | grep -v Symmetrix | grep -v Director | grep -v assigned > ${tmpdir}/3564_noassign.txt
pbrun symmaskdb -sid 3943 list no_assignment | sort -u | grep -v Symmetrix | grep -v Director | grep -v assigned > ${tmpdir}/3943_noassign.txt
pbrun symmaskdb -sid 3550 list no_assignment | sort -u | grep -v Symmetrix | grep -v Director | grep -v assigned > ${tmpdir}/3550_noassign.txt

pbrun symdev -sid 3564 list -noport | grep 34526 | cut -c2-4 >> ${tmpdir}/3564_noassign.txt

pbrun symdev -sid 3544 list > ${tmpdir}/3544.txt
pbrun symdev -sid 3810 list > ${tmpdir}/3810.txt
pbrun symdev -sid 3564 list > ${tmpdir}/3564.txt
pbrun symdev -sid 3943 list > ${tmpdir}/3943.txt
pbrun symdev -sid 3550 list > ${tmpdir}/3550.txt

clear
echo Generating FDC Capacity Report...please wait...

CapT3=0
NumT3=0
NumMeta=0
echo Symmetrix 3544 > ${outfile}
for x in `cat ${tmpdir}/3544_noassign.txt|sed -e s/^M//`
do
if [ ! -z `grep ^0${x} ${tmpdir}/3544.txt` ]
then
        grep ^0${x} ${tmpdir}/3544.txt |awk '{print $6,$NF}'|read a b
        if [ ${b} -eq 3 -o ${b} -eq 734 ]
        then
                continue
        else
        if [ ${b} -gt 34526 ]
        then
                NumMeta=NumMeta+1
        fi
        CapT3=CapT3+b
        NumT3=NumT3+1
        fi
fi
done
CapT3=CapT3/1024
echo Number of unallocated Tier3 devs is ${NumT3} with a total capacity of ${CapT3} GB >> ${outfile}
echo Number of unallocated Tier3 Metas is ${NumMeta} >> ${outfile}

CapT3=0
NumT3=0
NumMeta=0
echo >> ${outfile}
echo Symmetrix 3810 >> ${outfile}
for x in `cat ${tmpdir}/3810_noassign.txt|sed -e s/^M//`
do
if [ ! -z `grep ^0${x} ${tmpdir}/3810.txt` ]
then
        grep ^0${x} ${tmpdir}/3810.txt |awk '{print $6,$NF}'|read a b
        if [ ${b} -eq 3 -o ${b} -eq 734 ]
        then
                continue
        else
        if [ ${b} -gt 34526 ]
        then
                NumMeta=NumMeta+1
        fi
        CapT3=CapT3+b
        NumT3=NumT3+1
        fi
fi
done
CapT3=CapT3/1024
echo Number of unallocated Tier3 devs is ${NumT3} with a total capacity of ${CapT3} GB >> ${outfile}
echo Number of unallocated Tier3 Metas is ${NumMeta} >> ${outfile}

CapT4=0
NumT4=0
NumMeta=0
echo >> ${outfile}
echo Symmetrix 3564 >> ${outfile}
for x in `cat ${tmpdir}/3564_noassign.txt|sed -e s/^M//`
do
if [ ! -z `grep ^0${x} ${tmpdir}/3564.txt` ]
then
        grep ^0${x} ${tmpdir}/3564.txt |awk '{print $6,$NF}'|read a b
        if [ ${b} -eq 3 -o ${b} -eq 734 ]
        then
                continue
        else
        if [ ${b} -gt 34526 ]
        then
                NumMeta=NumMeta+1
        fi
        CapT4=CapT4+b
        NumT4=NumT4+1
        fi
fi
done
CapT4=CapT4/1024
echo Number of unallocated Tier4 devs is ${NumT4} with a total capacity of ${CapT4} GB >> ${outfile}
echo Number of unallocated Tier4 Metas is ${NumMeta} >> ${outfile}

CapT4=0
NumT4=0
NumMeta=0
echo >> ${outfile}
echo Symmetrix 3943 >> ${outfile}
for x in `cat ${tmpdir}/3943_noassign.txt|sed -e s/^M//`
do
if [ ! -z `grep ^0${x} ${tmpdir}/3943.txt` ]
then
        grep ^0${x} ${tmpdir}/3943.txt |awk '{print $6,$NF}'|read a b
        if [ ${b} -eq 3 -o ${b} -eq 734 ]
        then
                continue
        else
        if [ ${b} -gt 34526 ]
        then
                NumMeta=NumMeta+1
        fi
        CapT4=CapT4+b
        NumT4=NumT4+1
        fi
fi
done
CapT4=CapT4/1024
echo Number of unallocated Tier4 devs is ${NumT4} with a total capacity of ${CapT4} GB >> ${outfile}
echo Number of unallocated Tier4 Metas is ${NumMeta} >> ${outfile}

CapT3=0
NumT3=0
NumMeta=0
echo >> ${outfile}
echo Symmetrix 3550 - Star >> ${outfile}
for x in `cat ${tmpdir}/3550_noassign.txt|sed -e s/^M//`
do
if [ ! -z `grep ^0${x} ${tmpdir}/3550.txt` ]
then
        grep ^0${x} ${tmpdir}/3550.txt |awk '{print $6,$NF}'|read a b
        if [ ${b} -eq 3 -o ${b} -eq 734 ]
        then
                continue
        else
        if [ ${b} -gt 34526 ]
        then
                NumMeta=NumMeta+1
        fi
        CapT3=CapT3+b
        NumT3=NumT3+1
        fi
fi
done
CapT3=CapT3/1024
echo Number of unallocated Tier3 devs is ${NumT3} with a total capacity of ${CapT3} GB >> ${outfile}
echo Number of unallocated Tier3 Metas is ${NumMeta} >> ${outfile}

# Cleanup files

rm ${tmpdir}/3544_noassign.txt
rm ${tmpdir}/3810_noassign.txt
rm ${tmpdir}/3564_noassign.txt
rm ${tmpdir}/3943_noassign.txt
rm ${tmpdir}/3550_noassign.txt
rm ${tmpdir}/3544.txt
rm ${tmpdir}/3810.txt
rm ${tmpdir}/3564.txt
rm ${tmpdir}/3943.txt
rm ${tmpdir}/3550.txt

# Exit
clear
echo FDC Symmetrix Free Capacity Report is ${outfile}
echo
