Zimbra Tips : Script to Check Mailbox Usage for Each User

Yesterday,  a friend of mine  asked me how to take all  data usage for each Zimbra user  for information and reporting purpose. Actually, all information about how many  mailboxes usages for each user on Zimbra Mail Server,  can be seen on the  Zimbra Admin | Server Statistics | Mailbox Quota.
zimbra-logoYou can see total quota and the quota already in use for each user. Although quite informative, it is not really flexible if we would like to use the data for other purposes. We must re-write the existing information or make a screenshot which will be difficult to be done if Zimbra has a large account.
To resolve this issue, we can utilize  Zimbra CLI and then create a small script  to find out how many mailboxes and the total quota usage for each user. Here’s an example of the command line :
su – zimbra

zmmailbox -z -m ahmad.iman@excellent.co.id gms

Command Line to see the total mailboxes

su - zimbra
zmprov ga vivianchow@excellent.co.id | grep zimbraMailQuota

From the  above example, we can create a simple script to looping all user mailbox and retrieve information about mailbox quota

vi /srv/quota-used.sh

paste the following code to the file you just created

#!/bin/bash
echo "Username           Total Quota         Usage"
zmprov -l gaa | while read ACCOUNT
 do
        QUOTA_TOTAL=`zmprov ga ${ACCOUNT} | grep "zimbraMailQuota" | cut -d ":" -f2`
        QUOTA_USAGE=`zmmailbox -z -m ${ACCOUNT} gms`
        echo "${ACCOUNT}    ${QUOTA_TOTAL}    ${QUOTA_USAGE}"
done

give executable permissions and run by using Zimbra permission

chmod +x /srv/quota-used.sh
su - zimbra
sh /srv/quota-used.sh

The above script  can be modified so that the result can be opened as csv file. Good luck and hopely it can be useful 😀 . 

Leave a Reply

Your email address will not be published. Required fields are marked *