
#!/bin/sh
# File	: show_mss01_access.sh
# By	: Maarten.deBoer@Atos.net, 210113
# Subject	: Script to show access (sessions) to nlnafvmss01 and "translate" the NL/A-numbers
#(0.2)	: Added session counter
PGM=`basename $0|cut -d\. -f1`
VER="0.2"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh -n"

#USERLIST="${HOME}/etc/${PGM}.list"
USERLIST="${HOME}/etc/create_mss01_access.list"
DONELIST="${HOME}/data/${PGM}.done"
FILER="nlnaf25"
VFILER="nlnafvmss01"
VF_UPPER=`echo ${VFILER}|tr [:lower:] [:upper:]`
MAILTO="maarten.deboer@atos.net"

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}|tee -a ${TMP}
if [ ! -f ${USERLIST} ]; then
  echo "  NO USERLIST (${USERLIST}) found. Exiting ..."|tee -a ${LOG}
  exit 3
fi

touch ${TMP}

${SSH} ${FILER} "vfiler run ${VFILER} cifs sessions" 2>&1 |grep ${VF_UPPER}|grep "("|sort|while read DEVICE USER REST
do
  USER=`echo ${USER}|sed "s/${VF_UPPER}//g"|sed "s/(//g"`
  NAME=`grep ${USER} ${USERLIST}|awk -F\; '{print $2}'`
  echo "  |${DEVICE}|${USER}|${NAME}|"|tee -a ${TMP}
done  # show sessions

ROW_CNT=`cat ${TMP}|grep "  |"|wc -l`
echo "    ${ROW_CNT} rows." |tee -a ${TMP}

if [ "${MAILTO}" != "" ]; then
  cat ${TMP}|mailx -s "MSS01 sessions [${PGM} v${VER}]" ${MAILTO}
  echo "  Mailed to ${MAILTO}"|tee -a ${LOG}
fi

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

