Script - courier-imap virtual mail accounts listing

I made this little script to get a daily report of the usage of our virtual mailboxes at work, the POP3 server is courier-imap. I don’t need to run any quota on the accounts but I just want to make sure people regularly check their mailboxes.

<code>#!/bin/sh

# Check storage used by virtual mail accounts under courier-imap

DOMAINS="domain1.be domain2.be"
TIMESTAMP=`date +%d/%m/%Y`

echo "REPORT DATE : $TIMESTAMP"
echo " "
for domains in $DOMAINS

do
echo "---------------------------"
echo "$domains"
echo "===================================================="
echo "Size               Accounts"
echo "---------------------------"
echo " "
du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | 
        egrep "/var/spool/postfix/vmail/$domains/[a-z]/" | 
        sed -re "s//var/spool/postfix/vmail/$domains/[a-z]///g" | 
        egrep "[0-9]{2,3}M" | 
        awk '{print $1, "               ",$2}' | 
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | 
        egrep "/var/spool/postfix/vmail/$domains/[a-z]/" | 
        sed -re "s//var/spool/postfix/vmail/$domains/[a-z]///g" | 
        egrep "[0-9]{1}.[0-9]{1}M" | 
        awk '{print $1, "       ",$2}' | 
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | 
        egrep "/var/spool/postfix/vmail/$domains/[a-z]/" | 
        sed -re "s//var/spool/postfix/vmail/$domains/[a-z]///g" | 
        egrep "[0-9]{3}K" | 
        awk '{print $1, "       ",$2}' | 
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | 
        egrep "/var/spool/postfix/vmail/$domains/[a-z]/" | 
        sed -re "s//var/spool/postfix/vmail/$domains/[a-z]///g" | 
        egrep -v "[0-9]{3}" | 
        egrep "[0-9]{2}K" | 
        awk '{print $1, "       ",$2}' | 
        sort -r

        echo " "
done</code>

Output looks like this :

<code>REPORT DATE : 17/01/2006

---------------------------
mac-s.be
====================================================
Size             Accounts
---------------------------
 
23M              admin
1.1M              admin
221K              admin
24K              admin
 
---------------------------
label-design.be
====================================================
Size             Accounts
---------------------------
 
20K              admin</code>



Thanks for reading this post!


Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!