
#!/bin/sh
# File	: get_CIFS-sessions_NFS-exports.sh
# By	: Maarten.deBoer@Atos.net, 120120
# Subject	: Script to get CIFS-sessions, NFS-export with hosts
#set -x
PGM="`basename $0|cut -d\. -f1`"
VERSION="0.1"
TMP="/tmp/${PGM}.$$"
FILERS="${HOME}/etc/filers"
SSH="/usr/bin/ssh -n"
MAILTO="maarten.deboer@atos.net"
FILTER="[1234567890]*"

FILTER="slb"

echo "# Filer ; " > ${TMP}
for FILER in `cat ${FILERS}|grep -v \^#`
do
  ${SSH} ${FILER} vfiler status|grep running|grep ${FILTER}|awk '{print $1}'|while read VFILER
  do
    echo "${FILER}/${VFILER} CIFS sessions: ; PC IP(PC Name);(user)" | tee -a ${TMP}
    ${SSH} ${FILER} vfiler run ${VFILER} cifs sessions|grep '('|sort -u|awk '{print ";"$1";"$2";"$3";"$4";"$5";"}' >> ${TMP}
    echo "${FILER}/${VFILER} NFS exports: ; Volume/Qtree ; Options" | tee -a ${TMP}
    ${SSH} ${FILER} vfiler run ${VFILER} exportfs| awk '{print ";"$1";"$2";"}' >> ${TMP}
    echo ";" >> ${TMP}
  done
done
echo " ;"
echo "# Produced by ${PGM} v${VERSION} at `hostname` at `date`"|tee -a ${TMP}

cat ${TMP}|uuencode ${PGM}.csv|mailx -s "CIFS-sessions & NFS-exports ${FILTER}.csv" ${MAILTO}

echo "Mailed to ${MAILTO} (with FILTER=${FILTER}) ."

rm ${TMP}
exit 0

