Frequently Asked Question

Commandline Listed Mailboxes and Quotas
Last Updated 3 hours ago

This article explains a virtualmin command pipeline that lists all email mailboxes for a domain along with their quota allocation and current usage, formatted as a readable table.


The Command

virtualmin list-users --domain somedomain.co.uk --email-only --multiline |
awk -F': ' '
/^    User:/ {
    if (email != "") {
        pct = (quota_bytes > 0) ? (used_bytes / quota_bytes * 100) : 0
        printf "%-40s %-8s %-8s %6.2f%%\n", email, quota, used, pct
    }
    email=quota=used=""
    quota_bytes=used_bytes=0
}
/^    Home quota:/       {quota=$2}
/^    Home quota used:/  {used=$2}
/^    Home byte quota:/  {quota_bytes=$2}
/^    Home byte quota used:/ {used_bytes=$2}
/^    Email address:/    {email=$2}
END {
    if (email != "") {
        pct = (quota_bytes > 0) ? (used_bytes / quota_bytes * 100) : 0
        printf "%-40s %-8s %-8s %6.2f%%\n", email, quota, used, pct
    }
}'

Notes and Caveats

  • Leading whitespace in values — because virtualmin --multiline indents its output, $2 will typically contain a leading space (e.g., alice@somedomain.co.uk). This is usually harmless for display purposes but should be trimmed if the output is being fed into another script. Use gsub(/^ /, "", $2) within each block to strip it.
  • Field separator collision — if any value itself contains a colon (unlikely for quota values, but possible in email addresses using unusual formats), awk will split on that colon too. In practice this is not an issue for standard Virtualmin mailbox output.
  • Root/sudo requirementvirtualmin CLI commands typically require root privileges or execution as the server administrator. Prefix with sudo if running as a non-root user:

This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK
Powered by GEN UK CLEAN GREEN ENERGY

Loading ...