
#!/bin/ksh
set +x
#--------------------------------------------------------------------------#
#                                                                          #
# Name: volresize.sh                                                       #
#                                                                          #
# Description: Script collects data about quota information, volume size   #
#              and resizes volumes is need be.                             #
#              Runs ad-hoc from command line and scheduled from crontab    #
#                                                                          #
# Version: 0.1                                                             #
#                                                                          #
# References:                                                              #
#                                                                          #
# Documentation:                                                           #
#                                                                          #
# Parameters: None                                                         #
#                                                                          #
# Usage: volresize.sh                                                      #
#                                                                          #
# Global Description:                                                      #
#                                                                          #
# Author(s): Atos Origin                                                   #
#                                                                          #
# Change log:                                                              #
# aut   date          vers   comments                                      #
# RtB   07-07-2009    0.1    Copy from make_report.sh                      #
#                                                                          #
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
# Read parameter                                                           #
#--------------------------------------------------------------------------#

#--------------------------------------------------------------------------#
# Initialize variabels                                                     #
#--------------------------------------------------------------------------#

DATE=`date +%Y%m%d`
MAILTO="gmnl-msscentral@atosorigin.com"
EXCL=${HOME}/etc/quota_exclude.lst
ERR=${HOME}/data/out/$DATE-volresize.err
TMP=${HOME}/data/out/$DATE-volresize.tmp


#--------------------------------------------------------------------------#
# Collect data of vfilers, volumes, qtrees, quotas and exportfs            #
#--------------------------------------------------------------------------#

for FILER in $(cat ${HOME}/etc/filers)
do
  for VFILER in `ssh ${FILER} vfiler status | grep -v vfiler0 | grep running | awk '{ print $1 }'`
  do
    for VOLUME in `ssh ${FILER} vfiler run ${VFILER} vol status | grep online | awk '{ print $1 }' | grep -v ^vol0 | /usr/xpg4/bin/grep -v -f ${EXCL} | sort`
    do
    QSTATUS=`ssh ${FILER} vfiler run ${VFILER} quota status ${VOLUME} 2>/dev/null | grep quotas | grep -v snapmirrored | awk '{print $4}' | cut -d. -f1`
      if test ${QSTATUS} 
      then
         if test ${QSTATUS} = off
         then
            echo "${VOLUME}" >> ${TMP}
         else
           for QTREE in `ssh ${FILER} vfiler run ${VFILER} quota report | grep /vol/${VOLUME} | awk '{print $4}'`
           do
             for QSIZE in `ssh ${FILER} vfiler run ${VFILER} quota report | grep /vol/${VOLUME} | grep ${QTREE} | awk '{print $6}'`
             do
               if test ${QSIZE} = '-'
               then
                  echo "${VOLUME}" >> ${TMP}
               fi
             done
           done
         fi
      fi
    done
  done
done

cat ${TMP} | sort | uniq > ${ERR}


#--------------------------------------------------------------------------#
# Calculate quota requirements for all volumes and resize accordingly      #
#--------------------------------------------------------------------------#

for FILER in $(cat ${HOME}/etc/filers)
do
  for VFILER in `ssh ${FILER} vfiler status | grep -v vfiler0 | grep running | awk '{ print $1 }'`
  do
    for VOLUME in `ssh ${FILER} vfiler run ${VFILER} vol status | grep online | awk '{ print $1 }' | grep -v ^vol0 | /usr/xpg4/bin/grep -v -f ${EXCL} | /usr/xpg4/bin/grep -v -f ${ERR} | sort`
    do
######Insert quota calculations 
      DFV=`ssh ${FILER} df -g ${VOLUME} | grep -v File | grep -v snapshot | awk '{print $5}' | cut -d% -f1`
      echo $DFV
      if test $DFV -lt 90
        then
           # Volume size equals the sum of the quota + snap reserve
############ Resize the volume if needed  
        else
           # Volume size equals the sum of the quota + 10% + snap reserve
############ Resize the volume if needed  
      fi
    done  
  done
done

exit



rm ${ERR}
rm ${TMP}

