
#!/bin/sh
# File	: get_routes.sh
# By	: Maarten.deBoer@Atos.net, 140317
# Subject	: Report vscan (@vfilers) items
#(0.2)	: Added vfiler route -s
PGM="`basename $0|cut -d\. -f1`" 
VER="0.2"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
FILERS="${HOME}/etc/filers"
SSH="/usr/bin/ssh -n"
HOSTNAME="`hostname|cut -d\. -f1`"
MAILTO="maarten.deboer@atos.net"
DATI="`date +%Y-%m-%d'_'%H-%M`"
CSV="/tmp/${PGM}_${DATI}.csv"

touch ${TMP} ${LOG} 
echo "# Filer;Date Time;Destination;Gateway;Flags;Refs;Use;Interface;" > ${TMP}
for FILER in `cat ${FILERS}|grep -v \^#`
do
  ${SSH} ${FILER} vfiler status|grep running|awk '{print $1}'|while read VFILER
  do
    echo "${FILER}/${VFILER};`date +%Y-%m-%d' '%H:%M`;"|tee -a ${TMP}
    ${SSH} ${FILER} vfiler run -q ${VFILER} route -s|egrep -v 'Routing|Internet|Destination'|awk '{print ";;"$1";"$2";"$3";"$4";"$5";"$6";"}'|tee -a ${TMP}

  done  # VFILER
done  # for FILER

if [ -s ${TMP} ]; then
  cp ${TMP} ${CSV}
  date|mailx -a ${CSV} -s "@${HOSTNAME}: Get routes [${PGM} v${VER}]" ${MAILTO}

fi  # -s ${TMP}

rm ${TMP} ${CSV}
exit 0

