
#!/bin/sh
# File	: get_vfiler_info.sh
# By	: Maarten.deBoer@AtosOrigin.com, 110104
# Subject	: Get all Vfilers from all filers + info

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

if [ "${1}" != "" ]; then
  FILTER="${1}"
fi

touch ${TMP} 

DATE="`date +%Y-%m-%d`"
TXT="${FILTER}_vfiler_info_${DATE}.txt"

echo "## ${TXT}" > ${TMP}
echo "#= Made by ${PGM} v${VERSION} at ${DATE} at ${HOSTNAME}" >> ${TMP}
echo "" >> ${TMP}

for FILER in `cat ${FILERS}|grep -v \^#|sort`
do
  echo "${FILER}:"
# When use of FILTER
  if [ "${FILTER}" = "" ]; then
    ${SSH} ${FILER} vfiler status|grep running|grep -v vfiler|awk '{print $1}'|while read VFILER
    do
      echo "${FILER}/${VFILER}:" | tee -a ${TMP}
      ${SSH} ${FILER} vfiler status -r ${VFILER}|egrep -ve 'Path|UUID'|tee -a ${TMP}
    done
  else
    ${SSH} ${FILER} vfiler status|grep running|grep -v vfiler|grep ${FILTER}|awk '{print $1}'|while read VFILER
    do
      echo "${FILER}/${VFILER}:" | tee -a ${TMP}
      ${SSH} ${FILER} vfiler status -r ${VFILER}|egrep -ve 'Path|UUID'|tee -a ${TMP}
    done
  fi
done

echo "Sending the output to ${MAILTO} ..."
cat ${TMP}|unix2dos|uuencode ${TXT}|mailx -s ":${HOSTNAME}: ${FILTER}vFiler info [${PGM} v${VERSION}]" ${MAILTO}

rm ${TMP}
exit 0

