Mailbox usage report

Revision as of 13:24, 27 June 2014 by Thom (talk | contribs)

A way to get an emailable report of all mailboxes in a domain, their quota, usage and account status, so a domain admin can review their accounts without having to login to zimbra. (most of this is the same as viewing quota usage in zimbra admin, but this was easier, as it can then be emailed on a schedule)

I saved this file in /opt/zimbra/backup/scripts/ as usagereport.sh, owned by zimbra.zimbra chmod 755 accountusage.sh

#!/bin/bash
output="/tmp/accountusage"
domain="yourdomainnamehere.com"
SendTo="zimbra_reports@$domain"

rm -f $output
touch $output

server=`zmhostname`
/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 " "`
status=`/opt/zimbra/bin/zmprov ga $user | grep  ^zimbraAccountStatus | cut -f2 -d " "`
echo "$user `expr $usage / 1024 / 1024`Mb `expr $quota / 1024 / 1024`Mb ($status account)" >> $output
done

cat $output | mail @SendTo -s"Mailbox Usages for $domain"


Then I just setup a cronjob (crontab -e as zimbra user) to run this at 4:01 every monday morning, and email it to them.
1 4 * * 1 /opt/zimbra/backup/scripts/accountusage.sh

You could easily modify this to run through each domain on your server, and send a report to each domain, if you wanted (just add another for loop)
The output looks something like this (alphabetically for all users)

user1@yourdomain.com 5Mb 100Mb (active account)
user2@yourdomain.com 77Mb 100Mb (active account)
user3@yourdomain.com 9Mb 100Mb (closed account)
user4@yourdomain.com 24Mb 100Mb (active account)
etc

They then can at a quick glance, see if there are any users nearing quota, or if a locked/closed account is using too much disk space and should be purged, etc! :)

Jump to: navigation, search