
#!/bin/sh
# File  : chk_env_status.sh
# By    : Maarten de Boer, 130324
# Subject       : Check environment status shelf & environment status chassis for errors
# set -x
#(0.2)	: Added GOOD
#(0.3),170511	: Added ping & EC
PGM="`basename $0|cut -d\. -f1`"
VER="0.2"
TMP="/tmp/${PGM}.$$"
HOSTNAME="`hostname`"
FILERS="${HOME}/etc/filers"
MAILTO="maarten.deboer@atos.net"
SSH="/usr/bin/ssh -n"

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

echo "FILERS=${FILERS}"

echo "`date` ${HOSTNAME}:${0} with ${FILERS} for ERRORs"|tee -a ${TMP}

for FILER in `cat ${FILERS}|grep -v \#`
do
  ping -c 1 ${FILER}
  EC=${?}
  if [ ${EC} -eq 0 ]; then
  echo "${FILER} environment status shelf ..."|tee -a ${TMP}
  ${SSH} ${FILER} environment status shelf|grep error|egrep -v 'none'|tee -a ${TMP}

  echo "${FILER} environment status chassis ..."|tee -a ${TMP}
  ${SSH} ${FILER} environment status chassis|grep -v "\------"|egrep -v 'normal|ok|OK|ON|PRESENT|NORMAL|State|Reading|GOOD'|tee -a ${TMP}
  else
    echo " No connection (ping) to ${FILER} ..."|tee -a ${TMP}
  fi  # EC

done  # for FILER

cat ${TMP}|mailx -s "[${PGM} v${VER}]" ${MAILTO}
echo "Output mailed to ${MAILTO}"

rm ${TMP}
exit 0

