
#!/bin/sh
# File  : get_cifs_sessions.sh
# By    : MaartenDeBoer.nl, 101214
# Subject       : Get CIFS sessions info

PGM="`basename $0|cut -d\. -f1`"
TMP="/tmp/${PGM}.$$"
LOG="$HOME/log/${PGM}.log"
FILERS="$HOME/etc/filers"
SSH="/usr/bin/ssh -n"
ASC="/tmp/${PGM}.asc"
#MAILTO="maarten.deboer@atos.net"
MAILTO="leo.vandenakker@atos.net maarten.deboer@atos.net"

touch ${TMP}

for FILER in `cat ${FILERS}|grep -v \^#|grep nlnaf5[1234] |sort`
do
  echo "${FILER}:" | tee -a ${TMP}
  ${SSH} ${FILER} vfiler status|grep running|grep -v vfiler|awk '{print $1}'|grep aip| while read VFILER
  do
    echo "${FILER}/${VFILER}:" | tee -a ${TMP}
#    ${SSH} ${FILER} vfiler run ${VFILER} cifs sessions -s | tee -a ${TMP}
    ${SSH} ${FILER} vfiler run ${VFILER} cifs sessions|tee -a ${TMP}
  done
done

PCUSERS="`grep pcuser ${TMP}|wc -l`"
ROOTUSERS="`grep root ${TMP}|wc -l`"
cp ${TMP} ${ASC}
chmod 777 ${ASC}
echo "`date` . # pcuser-sessions=${PCUSERS} . # root-sessions=${ROOTUSERS} . Details in attachment." | mailx -a ${ASC} -s "[${PGM}]" ${MAILTO}

rm ${TMP} ${ASC}
exit 0

