+91 – 7838219999

contact@nitinfotech.com

HomeTech SolutionsZimbraTop 5 Largest Mailboxes in Zimbra: How to List by Size 

Top 5 Largest Mailboxes in Zimbra: How to List by Size 

Monday, December 30, 2024

To list the top 5 Mailboxes in Zimbra by size using the zmprov command, you’ll need to follow a series of steps that involve gathering mailbox sizes, sorting them, and then displaying the top results. Here’s how you can achieve this using a bash script on a Zimbra server: 

1. List All Accounts

First, you need to get a list of all email accounts using the zmprov command. 

2. Check Mailboxes in Zimbra by sizes for Each Account

Use the zmmailbox command to get the size of each mailbox. 

3. Sort and Display the Top 5 Mailboxes

Sort the mailbox sizes and filter to display the top 5 largest mailboxes.

Step-by-Step Script

Here’s a bash script that automates these steps:

#!/bin/bash 
 
# Temporary file to store mailbox sizes 
temp_file="/tmp/mailbox_sizes.txt" 
 
# Get a list of all accounts 
zmprov -l gaa > /tmp/accounts_list.txt 
 
# Clear temporary file 
> $temp_file 
 
# Loop through each account and get its mailbox size 
while read -r account; do 
    # Get the mailbox size for each account 
    size=$(zmmailbox -z -m "$account" getMailboxSize | grep 'Total Size' | awk '{print $3}') 
     
    # If size is not empty, append account and size to the temp file 
    if [ -n "$size" ]; then 
        echo "$size $account" >> $temp_file 
    fi 
done < /tmp/accounts_list.txt 
 
# Sort the results by size in descending order and get the top 5 
echo "Top 5 mailboxes by size:" 
sort -k1 -n -r $temp_file | head -n 5 
 
# Clean up 
rm /tmp/accounts_list.txt 
rm $temp_file

Explanation:

1. Get List of Accounts: 

  • zmprov -l gaa lists all accounts and saves them to /tmp/accounts_list.txt.

2. Fetch Mailbox Sizes:

  • For each account, the zmmailbox -z -m “$account” getMailboxSize command retrieves the mailbox size. 
  • grep ‘Total Size’ | awk ‘{print $3}’ extracts the size. 

3. Store Sizes: 

  • The script appends the size and account to /tmp/mailbox_sizes.txt. 

4. Sort and Display:

  • sort -k1 -n -r sorts the results by size in descending order. 
  • head -n 5 filters to show the top 5 largest mailboxes. 

5. Clean Up:

  • Temporary files are removed after processing. 

6. Save the Script:

  • Save the script as top_mailbox_sizes.sh

7. Make it Executable: 

chmod +x top_mailbox_sizes.sh

8. Execute the Script: 

./top_mailbox_sizes.sh

This script will provide you with a list of the top 5 mailboxes by size, helping you identify the largest mailboxes on your Zimbra server.