
#!/bin/sh
# File	: cdot_atos_accounting_v2.sh
# By	: Maarten.deBoer@atos.net, 140909
# Subject	: Script to collect accounting information from cDOT filers. 
#		  Per cDOT-cluster (not per vfiler)
#		  In the accounting-v2 way 
#		  NO Storage-class in volumename. But combined Aggrname + Volumename  
# 		  And send it per mail to MSS-accounting-server
#Mod 0.2	: scp in stead of mailx
#(0.3	: Added ls -l
PGM="`basename $0|cut -d\. -f1`"
VER="0.3"
TMP="/tmp/${TMP}.$$"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh -n"
HOSTNAME="`hostname|cut -d\. -f1`"
DATADIR="${HOME}/data/out"

SCPUSER="receiver"
SCPHOST="nlxmssp1"
SCPDIR="/home/receiver/import/inventory/cdot/"

CLUSTERS="${HOME}/etc/clusters"

# MAIN
touch ${TMP}
echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}

for CLUSTER in `cat ${CLUSTERS}|grep -v ^#`
do
  echo "${CLUSTER} ..."
  echo "# `date` by ${PGM} v${VER} at ${HOSTNAME}" > ${DATADIR}/${CLUSTER}.asc
# option -field selects the items to be shown. NOT the order. That is FIXED
  ${SSH} ${CLUSTER} 'set -units KB -showseparator ";" ; volume show -state online -field vserver,aggregate,volume,type,total,used,percent-used'|grep -v 'Volume Name'|tee -a ${DATADIR}/${CLUSTER}.asc

# copy file by using SCP
  scp ${DATADIR}/${CLUSTER}.asc ${SCPUSER}@${SCPHOST}:${SCPDIR}
  echo "`date` Information SCP-ed to ${SCPUSER}@${SCPHOST}:${SCPDIR} "|tee -a ${LOG}
  ${SSH} ${SCPUSER}@${SCPHOST} ls -l ${SCPDIR}|tee -a ${LOG} 2>&1

done  # for CLUSTER

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

