
#!/bin/sh
# File	: get_filer_disktypes.sh
# By	: Maarten de Boer, 110404
# Subject	: Get filer disks types

PGM="`basename $0 | cut -d\. -f1`"
VERSION="0.1"
TMP="/tmp/${PGM}.$$"
MAILTO="maarten.deboer@atosorigin.com"
HOSTNAME="`hostname`"
MAIL=""
FILERS="$HOME/etc/filers"
CSV="${PGM}.csv"
SSH="/usr/bin/ssh -n"

USAGE()
{
  echo "Usage: $PGM [-h] [-V] [-x] [-f] [--help] [--mail]"
  echo "  Version: ${VERSION}"
  echo "  options:"
  echo "    -h : this help"
  echo "    -V : Version"
  echo "    -x : set -x"
  echo "    --help          : this help"
  echo "    --mail          : do send mail"
}

# Check options
while [ $# -gt 0 ]
  do
  case ${1} in
    --mail) MAIL=1 ;;
    -h | --help) USAGE; exit 1 ;;
    -V) echo "${PGM}: v${VERSION}"; exit 3 ;;
    -x)  set -x ;;
    *)  echo "Option $1 not known."; USAGE; exit 1 ;;
  esac
    shift
done


touch ${TMP}
echo "Filer ; Disk type ; Amount ; " | tee ${TMP}

for FILER in `cat ${FILERS}`
do
  # Get RAW disk cap
  ${SSH} ${FILER} sysconfig -r|grep -v FAILED|egrep 'dparity|parity|spare|data'|awk '{print $10}'|cut -d\/ -f1|tee ${TMP}.2 |sort -u|while read LINE
  do
    echo "${FILER} ; ${LINE}; \c" | tee -a ${TMP}
    echo "`grep ${LINE} ${TMP}.2 | wc -l`;" | tee -a ${TMP}

  done


done

if [ $MAIL ]; then
  echo "Sending the .CSV-output to ${MAILTO} ..."
  cat ${TMP}|uuencode ${CSV}|mailx -s ":${HOSTNAME}: Filers disk types [${PGM} v${VERSION}]" ${MAILTO}
fi

rm ${TMP} ${TMP}.2
exit 0

