Zimbra Mailbox Usages Report

Login sebagai user zimbra terus pindah directory ke /opt/zimbra/backup/scripts

# su - zimbra
$ cd /opt/zimbra/backup/scripts

create file gqu.sh

$ vim gqu.sh

#!/bin/bash
output="/tmp/accountusage.txt"
domain="abc.co.id"
SendTo="it@abc.co.id"
#SendTo="dgprasetya@abc.co.id"

rm -f $output
touch $output

server=`hostname`
/opt/zimbra/bin/zmprov gqu $server|grep $domain|awk {'print $1" "$3" "$2'}|sort|while read line
do
usage=`echo $line|cut -f2 -d " "`
quota=`echo $line|cut -f3 -d " "`
user=`echo $line|cut -f1 -d " "`

usageMB=`expr $usage / 1024 / 1024`
quotaMB=`expr $quota / 1024 / 1024`

percentUsage=`echo "scale=2; $usageMB / $quotaMB * 100" | bc | awk -F \. '{print $1}'`

status=`/opt/zimbra/bin/zmprov ga $user | grep  ^zimbraAccountStatus | cut -f2 -d " "`
#echo -e "$user\t\t\t`expr $usage / 1024 / 1024`Mb\t\t\t`expr $quota / 1024 / 1024`Mb\t\t($status account)" >> $output


#if [ $(echo "$percentUsage > 90" | bc -l ) -eq 1 ]; then
    echo -e "$user\t\t\t${usageMB}Mb\t\t\t${quotaMB}Mb\t\t($status account)\t\t${percentUsage}%" >> $output
    #echo "yes"
#else
#    echo "no" 
#fi

done

#cat $output | mail @SendTo -s"Mailbox Usages for $domain"
#echo | mutt -s "Zimbra Mailbox Usages for $domain" $SendTo -a $output  < $output

##sort tampilan berdasarkan persentase
##http://stackoverflow.com/questions/1037365/unix-sort-with-tab-delimiter
sortfile="/tmp/sortfilegqu.txt"
cat $output | sort -t$'\t' -k11 -n -r > $sortfile

##merapikan tampilan
## http://www.unix.com/showthread.php?t=117543
awkfile="/tmp/awkfilegqu.txt"
awk '{ x = $2"\t"$3"\t"$4"\t"$5"\t"$6; printf "%-40s %-10s\n", $1, x}' $sortfile > $awkfile

##kalo file report kosong, email tidak akan dikirim
if [ $(wc -l $awkfile | awk '{print $1}') -eq 0 ]; then
echo "not send";
else

##kirim email
#(echo "Subject: Zimbra Mailbox Usages for $domain";cat $awkfile ) | /opt/zimbra/postfix/sbin/sendmail $SendTo
(echo "Subject: Zimbra Mailbox Usages for $domain";echo "Content-Type: text/html";echo "MIME-Version: 1.0";echo "<pre>`cat $awkfile`</pre>" ) | /opt/zimbra/postfix/sbin/sendmail $SendTo

fi

set crontab:

20 3 * * * bash -x /opt/zimbra/backup/scripts/gqu.sh 2>&1 | tee /opt/zimbra/backup/scripts/logs/zimbra-gqu-`date +\%F`.txt

Ref: wiki zimbra dengan perubahan