#! /bin/bash
# afrihost - get break down to find what files taking up most space

USAGE="/usr/local/afribin/cpuser_spacecheck USERNAME"

if ! [ "$1" ] ; then
        echo $USAGE
        exit 1
fi

cPuser=$1

echo -e "\n=== CURRENT QUOTA ======\n"

repquota -a | grep  used  | head -n1
repquota /home -s | grep $cPuser  | tail -n1  

echo -e  "\n------------------------\n"
cd /home/"$cPuser"  ; ls -1  | xargs -i du -sh ./{}   | while read psize pdir ; do if  echo  "$psize $pdir"  | egrep 'M|G' ; then  find "$pdir"/*   -maxdepth 10 -type d  | xargs -i  du -sh {} | egrep 'M|G'  | grep -v "[0-9]\.[0-9]K"  | sort -k1h ; fi ; done | sort -k1n  | egrep '^.G|^..G|^...G|^.M|^..M|^...M' | sort -k1h

echo "=== cpanel quota info ==="
uapi --output=jsonpretty   --user=$cPuser Quota get_quota_info
