#! /bin/sh

#    Jul 10/18 - F.Majaess (revised for Science)
#    Nov 05/13 - F.Majaess

#id ownquota - Used to obtain disk space usage and quota limit setting.

#    AUTHOR  - F.Majaess

#hd  PURPOSE - "ownquota" script handles reporting disk space usage and,
#hd            if applicable, effective imposed quota limit.

#ex  EXAMPLE:
#ex 
#ex   ownquota 
#ex 
#ex      The above example leads to reporting disk space usage and, if 
#ex      applicable, effective imposed quota limit.

# set -x
LOGNAME=${LOGNAME:=`logname`}
# AWK=${AWK:='nawk'}
AWK=${AWK:='awk'}
echo '================================================='
echo '*** User usage stats for /home & /home/ords:'
echo '-------------------------------------------'
if [ -s "/fs/homeu1/eccc/crd/quota.txt" ] ; then
 cat /fs/homeu1/eccc/crd/quota.txt | egrep " Block Limits |^Name  |^${LOGNAME} "
 # cat /fs/homeu1/eccc/crd/ords/quota.txt | egrep "^${LOGNAME} "
 echo '*** User usage stats for SITESTORE3:'
 echo '-----------------------------------'
 if [ -s /fs/site3/eccc/crd/quota.txt ] ; then
  cat /fs/site3/eccc/crd/quota.txt  | egrep -v '   ssc_hpcs  ' | egrep " Block Limits |^Name  |^${LOGNAME} "
 else
  ssh -o LogLevel=error -n eccc-ppp3 'cat /fs/site3/eccc/crd/quota.txt' | egrep -v '   ssc_hpcs  ' | egrep " Block Limits |^Name  |^${LOGNAME} "
 fi
 echo '================================================='
 echo '*** User usage stats for SITESTORE4:'
 echo '-----------------------------------'
 if [ -s /fs/site4/eccc/crd/quota.txt ] ; then
  cat /fs/site4/eccc/crd/quota.txt  | egrep -v '   ssc_hpcs  ' | egrep " Block Limits |^Name  |^${LOGNAME} "
 else
  ssh -o LogLevel=error -n eccc-ppp4 'cat /fs/site4/eccc/crd/quota.txt' | egrep -v '   ssc_hpcs  ' | egrep " Block Limits |^Name  |^${LOGNAME} "
 fi
 echo '================================================='
 echo '*** User usage stats for lustre filesytem on BANTING:'
 echo '-------------------------------------------------'
 if [ -s /fs/xc3lustre/quota.txt ] ; then
  cat /fs/xc3lustre/quota.txt | egrep "^Username  |^${LOGNAME} "
 else
  ssh -o LogLevel=error -n banting ' [ -s /fs/xc3lustre/quota.txt ] && cat /fs/xc3lustre/quota.txt || echo "" ' | egrep "^Username  |^${LOGNAME} "
 fi
 echo '================================================='
 echo '*** User usage stats for lustre filesytem on DALEY:'
 echo '-------------------------------------------------'
 if [ -s /fs/xc4lustre/quota.txt ] ; then
  cat /fs/xc4lustre/quota.txt | egrep "^Username  |^${LOGNAME} "
 else
  ssh -o LogLevel=error -n daley ' [ -s /fs/xc4lustre/quota.txt ] && cat /fs/xc4lustre/quota.txt || echo "" ' | egrep "^Username  |^${LOGNAME} "
 fi
 echo '================================================='
fi
