
#!/bin/sh
# File	: get_mc_tape_information.sh
# By	: MaartenDeBoer.nl, 090815
# Subject	: Get MC and tape config information
#Mod(02)	: In CSV-format

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


for FILER in `cat ${FILERS}`
do
#  echo "# Filer ${FILER} tape config & state (filer>storage show tape):" | tee -a ${TMP}
  echo "${FILER};" | tee -a ${TMP}
  ${SSH} ${FILER} storage show tape |while read LINE
  do
#   if line <> "" then add ;
    if [ "$LINE" != "" ]; then
      echo "$LINE;" >> ${TMP}
    else
#      echo "${FILER};" >> ${TMP}
      echo "" >> ${TMP}
    fi
  done

#  echo "Filer ${FILER} MC config & state (filer>storage show mc):" | tee -a ${TMP}
#  ssh -n ${FILER} storage show mc | tee -a ${TMP}
#  echo "Filer ${FILER} Displays tape library information (filer>sysconfig -m):" | tee -a ${TMP}
#  ssh -n ${FILER} sysconfig -m | tee -a ${TMP}
#  echo "Filer ${FILER} Displays device and configuration information for each tape drive. (filer>sysconfig -t):" | tee -a ${TMP}
#  ssh -n ${FILER} sysconfig -t | tee -a ${TMP}

#  echo ${HR} | tee -a ${TMP}
done


if [ ${MAIL} ]; then
  echo "# Produced by ${PGM} at ${HOSTNAME} at `date +%Y-%m-%d' '%H:%M`" >> ${TMP}
cat ${TMP} | nawk 'BEGIN {RS=""}
{
  t=0
  while (++t<=NF) {printf "%s ", $t}
  printf "\n"
}'file |sed -e 's/Tape Drive://'|sed -e 's/Description://'|sed -e 's/Serial Number://'|sed -e 's/WWNN://'|sed -e 's/WWPN://'|sed -e 's/Alias Name(s)://'|sed -e 's/Device State://'|uuencode ${CSV}|mailx -s ":${HOSTNAME}: Filer>storage show [${PGM} v${VERSION}]" ${MAILTO}

echo "Mailed to ${MAILTO} ..."

fi

rm ${TMP}
exit 0

