
#!/bin/sh
# File	: netapp-7mode_get_filer_inventory_files.sh
# By	: Maarten.deBoer@Atos.net, 091125
# Subject	: Get filer information in .ASC(.TXT) / .CSV in a tar-file
#
# (0.2)	: Added; useradmin group, role & ${FILER} at .CVS, RLM status, route -s
# (0.3)	: Added; ifconfig -a, /etc/hosts, rc, vif status
# (0.4) : ${FUSER} added & test for uuencode + quota, df -g & -s awk extended. Options & /etc/hosts & LUNs added
#(0.5)  : Added; snap list, nbtstat, vscan, ping -c1, usermap.cfg
#{0.6)	: Name change get_more_filer_info.sh|get_filer_info.sh -> get_filer_inventory.sh. Added ${UNIX2DOS} |${UUENC} .asc
#(0.7)	: Place all files in 1 zip
#(0.8)	: Added `storage show tape | mc` & ZIPFILE, vfiler status -a, SNMP
#(0.9)	: Added vfilers
#(0.10)	: Renamed to get_filer_inventory_files.sh (from get_filer_inventory.sh)
#(0.11)	: $PING added
#(0.12) : Added; for FILER in `cat ${FILERS}|grep -v \^#|awk -F\; '{print $1}'|sort` & exit 0 at and & `type ping`
#(0.13)	: Added USAGE & options + -f(ilter)
#(0.14) : Added sysconfig -v (For CJ Grothaus)
#(0.15) : Added LOG
#(0.16)	: Added Vfilers (for Replace-FSOD-filers project)
#(0.17) : Added aggr show_space
#(0.18) : Added -e (ETC file)
#(0.19}	: mailx -a added (RHEL6)
#(0.20}	: Added --toll + ${SUBJECT}. Changed .asc into .asc (so windword can be related to .acs)
#(0.21) : Mod. All ASCii; UNIX2DOS rem.; Add `aggr statys -v`; zip -> tar
#(0.22)	: Added iscsi. VERSION -> VER, Added '|grep running'
#(0.23)	: Mod. USAGE. rm /tmp/${ZIPFILE}, Added vfiler0 (rem grep -v vfiler)
#(0.24)	: Add SCP, uptime, messages-file & Need to give ONE option
#(0.25)	: Added --logfiles (LOGFILES)
#(0.26)	: Remove check by ping (did not work with filers nlnaf63+64) change to check by SSH
#	: Remove PING & TOLL
#(0.27)	:  Add sysconfig's
#
#(1.0),160614	: Made the 1st operational release (and renamed to netapp-7mode_get_filer_inventory_files). As part of MAS2ATF (2016-06-14)
#(1.1),160614	: Added: ${LOGDIR}, 'bmc status', 'sp status' & 'system node service-processor show'
#(1.2),160614	: Mode TARFILE="FSOD-Inventory-NetApp-7mode-v
#(1.3),160711	: Some mod of var places in begin of script
#(1.4),180315	: Added some comments & possibility to used RCfile. FUSER -> FFUSER. Added "ls -l", Mod. TARFILE-name
#set -x
PGM="`basename $0|cut -d\. -f1`" 
VER="1.4"
UUENC="uuencode"
SSH="ssh -n"
PING="ping"
MAIL=""
FILTER="[?]*"
TAR="/bin/tar"
USESCP=""
LOGFILES=""
RCFILE="${HOME}/etc/${PGM}.rc"

# The following VARs might be changed. Also by using them in RCfile $HOME/etc/${PGM}.rc
#
# FILERS = File with names of the filers. 1 per line
FILERS="${HOME}/etc/filers"
# FUSER = User to SSH to the FILER (NetApp-7-mode-system). When Linux-user is the same as filer-user. This USER can be empty
FUSER=""
# MAILTO = Address where tar file is mailed to. When -m | --mail option is used.
#  And where error-message "Problem with connection to" is send to (even with options -m). So a valid address is advised.
MAILTO="maarten.deboer@atos.net"
# Dir.name of LOGfile. When an (application) user is used with a log/-dir. Then does not need to be changed.
LOGDIR="${HOME}/log"
# When LOGDIR is set correctly. This does not need to be set
LOG="${LOGDIR}/${PGM}.log"
# TARDIR need to be set when /tmp is to small for the tar-file
TARDIR="/tmp"
# TMPDIR need to be set when /tmp is to small for all the filer information files.
TMPDIR="/tmp/${PGM}.$$"
# SCPUSER = User which is used at the MDR-destination-host
SCPUSER="receiver"
# SCPHOST = MDR-destination-host
SCPHOST="nlxmssp1"
# SCPDIR = MDR-destination-dir
SCPDIR="/home/receiver/import/inventory/filers/"

PATH="${PATH}:/usr/bin:/appl/tsu/bin:/usr/sbin:$HOME/bin"

mkdir -p ${TMPDIR}

# Functions
USAGE()
{
  echo "Usage: ${PGM} <option(s)>"
  echo "  Version: ${VER}"
  echo "  options           :"
  echo "    -e              : specify Etc-file (${FILERS})"
  echo "    -f              : filter filername (${FILTER})"
  echo "    -h | --help     : this help"
  echo "    -l | --logfiles : adds (messages & snapmirror) Logfiles in inventory"
  echo "    -m | --mail     : do send mail"
  echo "    -r              : specify Rc-file (${RCFILE})"
  echo "    -s | --scp      : used SCP for copying (to ${SCPUSER}@${SCPHOST}:${SCPDIR})"
  echo "    -V              : Version"
  echo "    -x              : set -x"
  echo "    --logfiles      : add (message & snapmirror) LOGFILES to inventory-file"
  echo "    --mailto        : change MAILTO address & do send mail (${MAILTO})"
}

## MAIN
# Check options
if [ ${#} -eq 0 ]; then
  echo "No option(s) given. So not to know what to do. Exiting..."; echo; USAGE;
  exit 1
fi
while [ ${#} -ge 1 ]
  do
  case $1 in
    -e) FILERS=${2}; shift ;;
    -r) RCFILE=${2}; shift ;;
    -f) FILTER=${2}; shift ;;
    -h | --help) USAGE; exit 1 ;;
    -m | --mail) MAIL=1; shift ;;
    -l | --logfiles) LOGFILES="1"; shift ;;
    -s | --scp) USESCP=1;;
    --mailto) MAILTO=${2}; MAIL=1; shift ;;
    -V) echo "${PGM}: v${VER}"; exit 3 ;;
    -x)  set -x ;;
    *)  echo "Option $1 not known."; USAGE; exit 1 ;;
  esac
    shift
done


if [ ! -d ${LOGDIR} ]; then
  mkdir -p ${LOGDIR}
fi
echo "`date` ${PGM} started" | tee -a ${LOG}

if [ -f ${RCFILE} ]; then
  echo "  Using RCFILE ${RCFILE}"|tee -a ${LOG}
  . ${RCFILE}
fi

echo "FILERS=${FILERS}" | tee -a ${LOG}
echo "FILTER=${FILTER}" | tee -a ${LOG}
echo "LOG=${LOG}" | tee -a ${LOG}
echo "MAILTO=${MAILTO}" | tee -a ${LOG}
echo "MAIL=${MAIL}" | tee -a ${LOG}
echo "FUSER=${FUSER}" | tee -a ${LOG}
echo "USESCP=${USESCP}" | tee -a ${LOG}
echo "SCPUSER=${SCPUSER}" | tee -a ${LOG}
echo "SCPHOST=${SCPHOST}" | tee -a ${LOG}
echo "SCPDIR=${SCPDIR}" | tee -a ${LOG}
echo "TARDIR=${TARDIR}" | tee -a ${LOG}
echo "TMPDIR=${TMPDIR}" | tee -a ${LOG}

sleep 1

# Test if uuencode exists. Otherwise use tee
type ${UUENC} 1> /dev/null 2>&1
EC=$?
if [ ${EC} -eq 0 ]; then
  UUENC="`type uuencode | awk '{print $3}'`"
else
  UUENC="tee"
fi
echo ${UUENC}|tee -a ${LOG}

# Check ${FILERS} file
if [ ! -f ${FILERS} ]; then
  echo "  Etc-file (${FILERS}) not found. Exiting ..."|tee -a ${LOG};exit 2;
fi

# Start getting info
for FILER in `cat ${FILERS}|grep -v \^#|grep ${FILTER}|awk -F\; '{print $1}'|sort`
do
  echo "`date` Filer ${FILER}..."|tee -a ${LOG}
# Check is filer is reachable & hase the same name
  ANSW="`${SSH} ${FILER} hostname`"
  if [ "${FILER}" = "${ANSW}" ]; then
    TARFILE="NetApp-Inventory-7mode-v${VER}-${FILER}.tgz"
    ${SSH} ${FUSER}${FILER} uptime > ${TMPDIR}/${FILER}_uptime.asc
# Displays very  detailed  information  about each I/O device.
    ${SSH} ${FUSER}${FILER} sysconfig -a > ${TMPDIR}/${FILER}_sysconfig-a.asc
# Displays  RAID  configuration  information.
    ${SSH} ${FUSER}${FILER} sysconfig -r > ${TMPDIR}/${FILER}_sysconfig-r.asc
# Displays  detailed  information  about each I/O device.
    ${SSH} ${FUSER}${FILER} sysconfig -v > ${TMPDIR}/${FILER}_sysconfig-v.asc
# Displays vital product information for each disk.
    ${SSH} ${FUSER}${FILER} sysconfig -d > ${TMPDIR}/${FILER}_sysconfig-d.asc
# Displays  tape  library information.
    ${SSH} ${FUSER}${FILER} sysconfig -m > ${TMPDIR}/${FILER}_sysconfig-m.asc
# Displays  device and configuration information for each tape drive.
    ${SSH} ${FUSER}${FILER} sysconfig -t > ${TMPDIR}/${FILER}_sysconfig-t.asc
    ${SSH} ${FUSER}${FILER} rdfile /etc/rc > ${TMPDIR}/${FILER}_rc.asc
    ${SSH} ${FUSER}${FILER} rdfile /etc/hosts > ${TMPDIR}/${FILER}_hosts.asc
    ${SSH} ${FUSER}${FILER} rdfile /etc/hosts.equiv > ${TMPDIR}/${FILER}_hosts-equiv.asc
    if [ ${LOGFILES} ]; then
      ${SSH} ${FUSER}${FILER} rdfile /etc/messages > ${TMPDIR}/${FILER}_messages.asc
      ${SSH} ${FUSER}${FILER} rdfile /etc/log/snapmirror > ${TMPDIR}/${FILER}_snapmirror-log.asc
    fi  # LOGFILES
    ${SSH} ${FUSER}${FILER} ifconfig -a > ${TMPDIR}/${FILER}_ifconfig-a.asc
    ${SSH} ${FUSER}${FILER} vif status > ${TMPDIR}/${FILER}_vif-status.asc
    ${SSH} ${FUSER}${FILER} useradmin user list > ${TMPDIR}/${FILER}_useradmin-user-list.asc
    ${SSH} ${FUSER}${FILER} useradmin group list > ${TMPDIR}/${FILER}_useradmin-group-list.asc
    ${SSH} ${FUSER}${FILER} useradmin role list > ${TMPDIR}/${FILER}_useradmin-role-list.asc
    ${SSH} ${FUSER}${FILER} exportfs > ${TMPDIR}/${FILER}_exportfs.asc
    ${SSH} ${FUSER}${FILER} cifs shares > ${TMPDIR}/${FILER}_cifs-shares.asc
    ${SSH} ${FUSER}${FILER} license > ${TMPDIR}/${FILER}_license.asc
    ${SSH} ${FUSER}${FILER} vfiler status -a > ${TMPDIR}/${FILER}_vfiler-status-a.asc
    ${SSH} ${FUSER}${FILER} rlm status > ${TMPDIR}/${FILER}_rlm-status.asc
    ${SSH} ${FUSER}${FILER} vol status -v > ${TMPDIR}/${FILER}_vol-status-v.asc
    ${SSH} ${FUSER}${FILER} vol status|grep ' root' > ${TMPDIR}/${FILER}_root-volume.asc
    ${SSH} ${FUSER}${FILER} options > ${TMPDIR}/${FILER}_options.asc
    ${SSH} ${FUSER}${FILER} route -s > ${TMPDIR}/${FILER}_route-s.asc
    ${SSH} ${FUSER}${FILER} route -sn > ${TMPDIR}/${FILER}_route-sn.asc
    ${SSH} ${FUSER}${FILER} lun show > ${TMPDIR}/${FILER}_lun-show.asc
# iSCSI
    ${SSH} ${FUSER}${FILER} iscsi status > ${TMPDIR}/${FILER}_iscsi-status.asc
    ${SSH} ${FUSER}${FILER} iscsi alias > ${TMPDIR}/${FILER}_iscsi-alias.asc
    ${SSH} ${FUSER}${FILER} iscsi connection show > ${TMPDIR}/${FILER}_iscsi-connection-show.asc
    ${SSH} ${FUSER}${FILER} iscsi initiator show > ${TMPDIR}/${FILER}_iscsi-initiator-show.asc
    ${SSH} ${FUSER}${FILER} iscsi interface accesslist show > ${TMPDIR}/${FILER}_iscsi-interface-accesslist-show.asc
    ${SSH} ${FUSER}${FILER} iscsi interface show > ${TMPDIR}/${FILER}_iscsi-interface-show.asc
    ${SSH} ${FUSER}${FILER} iscsi isns show > ${TMPDIR}/${FILER}_iscsi-isns-show.asc
    ${SSH} ${FUSER}${FILER} iscsi nodename > ${TMPDIR}/${FILER}_iscsi_nodename.asc
    ${SSH} ${FUSER}${FILER} iscsi portal show > ${TMPDIR}/${FILER}_iscsi-portal-show.asc
    ${SSH} ${FUSER}${FILER} iscsi security show > ${TMPDIR}/${FILER}_iscsi-security-show.asc
    ${SSH} ${FUSER}${FILER} iscsi session show > ${TMPDIR}/${FILER}_iscsi-session-show.asc
    ${SSH} ${FUSER}${FILER} iscsi stats > ${TMPDIR}/${FILER}_iscsi-stats.asc
    ${SSH} ${FUSER}${FILER} iscsi tpgroup show > ${TMPDIR}/${FILER}_iscsi-tpgroup-show.asc
    ${SSH} ${FUSER}${FILER} iscsi tpgroup alua show > ${TMPDIR}/${FILER}_iscsi-tpgroup-alua-show.asc
#
    ${SSH} ${FUSER}${FILER} vscan > ${TMPDIR}/${FILER}_vscan.asc
    ${SSH} ${FUSER}${FILER} nbtstat > ${TMPDIR}/${FILER}_nbtstat.asc
    ${SSH} ${FUSER}${FILER} rdfile /etc/usermap.cfg > ${TMPDIR}/${FILER}_usermap-cfg.asc
    ${SSH} ${FUSER}${FILER} sis config > ${TMPDIR}/${FILER}_sis-config.asc
    ${SSH} ${FUSER}${FILER} storage show mc > ${TMPDIR}/${FILER}_storage-show-mc.asc
    ${SSH} ${FUSER}${FILER} storage show tape > ${TMPDIR}/${FILER}_storage-show-tape.asc
    ${SSH} ${FUSER}${FILER} snmp > ${TMPDIR}/${FILER}_snmp.asc
    ${SSH} ${FUSER}${FILER} aggr show_space -k > ${TMPDIR}/${FILER}_aggr-show-space-k.asc
    ${SSH} ${FUSER}${FILER} aggr status -v > ${TMPDIR}/${FILER}_aggr-status-v.asc

    ${SSH} ${FUSER}${FILER} snap sched > ${TMPDIR}/${FILER}_snap-sched.asc
    echo "Getting a snap list can take a while ..."
    ${SSH} ${FUSER}${FILER} snap list > ${TMPDIR}/${FILER}_snap-list.asc

    ${SSH} ${FUSER}${FILER} df -gA|awk '{print $1";"$2";"$3";"$4";"$5";"}' > ${TMPDIR}/${FILER}_aggr.csv
    ${SSH} ${FUSER}${FILER} df -Ak > ${TMPDIR}/${FILER}_df-Ak.asc
    ${SSH} ${FUSER}${FILER} df -g|awk '{print $1";"$2";"$3";"$4";"$5";"}' > ${TMPDIR}/${FILER}_volumes.csv
    ${SSH} ${FUSER}${FILER} df -k > ${TMPDIR}/${FILER}_df-k.asc
    ${SSH} ${FUSER}${FILER} df -s|awk '{print $1";"$2";"$3";"$4";"$5";"}' > ${TMPDIR}/${FILER}_sis.csv
    ${SSH} ${FUSER}${FILER} df -s > ${TMPDIR}/${FILER}_df-s.asc
    ${SSH} ${FUSER}${FILER} qtree status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}_qtrees.csv
    ${SSH} ${FUSER}${FILER} qtree status > ${TMPDIR}/${FILER}_qtree-status.asc
    ${SSH} ${FUSER}${FILER} quota report|awk '{print $1";"$2";"$3";"$4";"$5";"$6";"$7";"$8";"$9";"}' > ${TMPDIR}/${FILER}-quotas.csv
    ${SSH} ${FUSER}${FILER} quota report > ${TMPDIR}/${FILER}_quota-report.asc
    ${SSH} ${FUSER}${FILER} snapvault status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}_SnapVault-status.csv
    ${SSH} ${FUSER}${FILER} snapvault status > ${TMPDIR}/${FILER}_snapvault-status.asc 
    ${SSH} ${FUSER}${FILER} snapmirror status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}_SnapMirror-status.csv
    ${SSH} ${FUSER}${FILER} snapmirror status > ${TMPDIR}/${FILER}_snapmirror-status.asc
#
    ${SSH} ${FUSER}${FILER} 'bmc status' > ${TMPDIR}/${FILER}_bmc-status.asc
    ${SSH} ${FUSER}${FILER} 'sp status' > ${TMPDIR}/${FILER}_sp-status.asc
    ${SSH} ${FUSER}${FILER} 'system node service-processor show' > ${TMPDIR}/${FILER}_system-node-service-processor-show.asc

# Start vfiler part
  for VFILER in `${SSH} ${FILER} vfiler status|grep running|awk '{print $1}'`
  do
    echo "`date` vFiler ${FILER}/${VFILER} ..."|tee -a ${LOG}
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs domaininfo  > ${TMPDIR}/${FILER}-${VFILER}_cifs-domaininfo.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs homedir  > ${TMPDIR}/${FILER}-${VFILER}_cifs-homedir.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs nbalias  > ${TMPDIR}/${FILER}-${VFILER}_cifs-nbalias.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs prefdc print  > ${TMPDIR}/${FILER}-${VFILER}_cifs-prefdc_print.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs sessions  > ${TMPDIR}/${FILER}-${VFILER}_cifs-sessions.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs shares  > ${TMPDIR}/${FILER}-${VFILER}_cifs-shares.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} cifs stat  > ${TMPDIR}/${FILER}-${VFILER}_cifs-stat.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} dns info  > ${TMPDIR}/${FILER}-${VFILER}_dns-info.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} exportfs  > ${TMPDIR}/${FILER}-${VFILER}_exportfs.asc
# iSCSI
#
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi status > ${TMPDIR}/${FILER}-${VFILER}_iscsi-status.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi alias > ${TMPDIR}/${FILER}-${VFILER}_iscsi-alias.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi connection show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-connection_show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi initiator show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-initiator_show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi interface accesslist show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-interface-accesslist-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi interface show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-interface-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi isns show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-isns-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi nodename > ${TMPDIR}/${FILER}-${VFILER}_iscsi_nodename.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi portal show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-portal-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi security show > ${TMPDIR}/${FILER}-${VFILER}_iscsi_security_show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi session show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-session-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi stats > ${TMPDIR}/${FILER}-${VFILER}_iscsi_stats.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi tpgroup show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-tpgroup-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} iscsi tpgroup alua show > ${TMPDIR}/${FILER}-${VFILER}_iscsi-tpgroup-alua-show.asc
#
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} lun show  > ${TMPDIR}/${FILER}-${VFILER}_lun-show.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} nbtstat  > ${TMPDIR}/${FILER}-${VFILER}_nbtstat.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} nis info  > ${TMPDIR}/${FILER}-${VFILER}_nis-info.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} nfs stat  > ${TMPDIR}/${FILER}-${VFILER}_nfs-stat.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} options  > ${TMPDIR}/${FILER}-${VFILER}_options.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} route -s  > ${TMPDIR}/${FILER}-${VFILER}_route-s.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} route -sn  > ${TMPDIR}/${FILER}-${VFILER}_route-sn.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} secureadmin status  > ${TMPDIR}/${FILER}-${VFILER}_secureadmin-status.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} useradmin user list  > ${TMPDIR}/${FILER}-${VFILER}_useradmin-user-list.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} useradmin group list  > ${TMPDIR}/${FILER}-${VFILER}_useradmin-group-list.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} useradmin role list  > ${TMPDIR}/${FILER}-${VFILER}_useradmin-role-list.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} vscan  > ${TMPDIR}/${FILER}-${VFILER}_vscan.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} ypwhich  > ${TMPDIR}/${FILER}-${VFILER}_ypwhich.asc

    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} qtree status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}-${VFILER}_qtrees.csv
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} qtree status > ${TMPDIR}/${FILER}-${VFILER}_qtree-status.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} quota report|awk '{print $1";"$2";"$3";"$4";"$5";"$6";"$7";"$8";"$9";"}' > ${TMPDIR}/${FILER}-${VFILER}_quotas.csv
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} quota report > ${TMPDIR}/${FILER}-${VFILER}_quota-report.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} snapvault status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}-${VFILER}_SnapVault-status.csv
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} snapvault status > ${TMPDIR}/${FILER}-${VFILER}_snapvault-status.asc
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} snapmirror status|awk '{print $1";"$2";"$3";"$4";"}' > ${TMPDIR}/${FILER}-${VFILER}_SnapMirror-status.csv
    ${SSH} ${FUSER}${FILER} vfiler run -q ${VFILER} snapmirror status > ${TMPDIR}/${FILER}-${VFILER}_snapmirror-status.asc

# Get vfiler-vol0-etc dir
    VFILERETCDIR="`${SSH} ${FILER} vfiler status -r ${VFILER}|grep etc|awk '{print $2}'`"
    ${SSH} ${FILER} rdfile ${VFILERETCDIR}/etc/usermap.cfg  > ${TMPDIR}/${FILER}-${VFILER}_usermap-cfg.asc

  done

# Zipping & mailing
    cd  ${TMPDIR}
    ${TAR} cvzf ${TARDIR}/${TARFILE} *
    RHREL="`/bin/rpm -qa|grep redhat-release|cut -d\- -f4| grep -i server`"
## Subject
    SUBJECT="@${HOSTNAME}: Inventory of ${FILER} in file ${TARFILE} [${PGM} v${VER}]"

    if [ ${MAIL} ]; then
      if [ "${RHREL}" = "5Server" ]; then
        cat ${TARDIR}/${TARFILE}|${UUENC} ${TARFILE}|mailx -s "${SUBJECT}" ${MAILTO}
      fi
      if [ "${RHREL}" = "6Server" ]; then
        echo "${PGM}:${TARFILE} [${PGM} v${VER}] at `date`"|mailx -s "${SUBJECT}" -a ${TARDIR}/${TARFILE} ${MAILTO}
      else
        echo "${PGM}:${TARFILE} [${PGM} v${VER}] at `date`"|mailx -s "${SUBJECT}" -a ${TARDIR}/${TARFILE} ${MAILTO}
      fi
      echo "`date` Tar-file mailed to ${MAILTO}"|tee -a ${LOG}
    fi  #  MAIL

# copy file by using SCP
    if [ ${USESCP} ]; then
      scp ${TARDIR}/${TARFILE} ${SCPUSER}@${SCPHOST}:${SCPDIR}
      echo "`date` Information SCP-ed to ${SCPUSER}@${SCPHOST}:${SCPDIR} ; List: "|tee -a ${LOG}
      ${SSH} ${SCPUSER}@${SCPHOST} "ls -l ${SCPDIR}/${TARFILE}" >> ${LOG} 
    fi  # USESCP

# Cleaningup Filer info
    rm ${TARDIR}/${TARFILE}
    rm ${TMPDIR}/${FILER}*

  else
    echo "  Problem with connection to ${FILER} (ANSW=${ANSW})"|tee -a ${LOG}|mailx -s "[${PGM} v${VER}]" ${MAILTO}
  fi  # Check by SSH
done  # for FILER

# Clean-up
if [ "${TMPDIR}" != "" ]; then
  echo "  Cleaningup ${TMPDIR} ..."
  rm -rf ${TMPDIR}
fi
echo "`date` ${PGM} v${VER} finished. "|tee -a ${LOG}
exit 0

