
#!/bin/sh
# File	: chk_snapmirror-frequency.sh
# By	: Maarten.deBoer@Atos.net, 161026
# Subject	: Script to check SnapMirror frequencies (sometimes at DR the frequency is not set right and becomse the default)
PGM="`basename $0|cut -d\. -f1`"
VER="0.1"
TMP="/tmp/${PGM}.$$"
HOSTNAME="`hostname|cut -d\. -f1`"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh -n"
MAIL=""
MAILTO="maarten.deboer@atos.net"
FILTER="[?]*"
DATE="`date +%Y-%m-%d`"

USAGE()
{
  echo "Usage: ${PGM} [options]"
  echo "  Version: ${VERSION}"
  echo "  options          :"
  echo "    -f             : Filter filername (${FILTER})"
  echo "    -h | --help    : this help"
  echo "    -m | --mail    : do send Mail"
  echo "    --mailto       : change MAILTO address & do send mail (${MAILTO})"
  echo "    -V             : Version"
  echo "    -x             : set -x"
}

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

echo "`date` ${PGM} v${VER} started." | tee -a ${LOG}

echo "  For ${FILER} "|tee -a ${LOG}

if [ ${ALLVFILERS} ]; then
  for VFILER in `${SSH} ${FILER} vfiler status|grep -v vfiler|grep running|awk '{print $1}'`
  do
    echo "  ${FILER}/${VFILER}:"|tee -a ${LOG} ${TMP}
    ${SSH} ${FILER} vfiler run ${VFILER} options cifs.per_client_stats.enable on
    sleep 60
    ${SSH} ${FILER} vfiler run -q ${VFILER} cifs top -s ops -n ${TOPNR}|tee -a ${TMP}
    ${SSH} ${FILER} vfiler run ${VFILER} options cifs.per_client_stats.enable off 
    date | tee -a ${TMP}
  done  # for VFILER
else
  echo "  ${FILER}/${VFILER}:"|tee -a ${LOG} ${TMP}
  ${SSH} ${FILER} vfiler run ${VFILER} options cifs.per_client_stats.enable on
  sleep 60
  ${SSH} ${FILER} vfiler run -q ${VFILER} cifs top -s ops -n ${TOPNR}|tee -a ${TMP}
  ${SSH} ${FILER} vfiler run ${VFILER} options cifs.per_client_stats.enable off 
  date | tee -a ${TMP}
fi  # ${ALLVFILERS}

cat ${TMP} >> ${DAYFILE}

if [ ${MAIL} ]; then
  date | mailx -a ${DAYFILE} -s "@${HOSTNAME}: CIFS top ${TOPNR} OPS from ${FILER} at ${DATE} [${PGM} v${VER}]" ${MAILTO}
  echo "`date` mailed to ${MAILTO}"|tee -a ${LOG}
fi  # MAIL

rm ${TMP}
echo "`date` finished." | tee -a ${LOG}
exit 0

