• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

CLI command or SQL query to find the size of a mailbox

Miguel_Tellería

Basic Pleskian
Plesk 12.0.18 on Centos 6.6.

Dear all,

In order to do automate some statistics i would like to have a quick way to see the size the mailboxes.

I know that I could execute a du -shc under /var/qmail/mailnames/<domain>/<mailbox> but for large mailboxes it will take a lot of time.

On the other hand Plesk reports mailbox sizes and occupation very fast (although not always up to date as I have noticed). This is the data that I would like to fetch which is good enough for my purposes.

I have tried the output of /usr/local/psa/bin/mail --info but it doesn't have that value. Is there another way to obtain it?

Regards,

Miguel Telleria
 
[root@ppu12-0 ~]# /usr/local/psa/admin/bin/mailbox_usage --help
Usage: mailbox_usage [--in-blocks]
STDIN should contain a set of '<domain_name> <mailbox_id> <mailbox_name>' strings
STDOUT will contain a set of '<counted_usage> <domain_name> <mailbox_id> <mailbox_name>' strings

[root@ppu12-0 ~]# /usr/local/psa/admin/bin/mailbox_usage --in-block
ppu12-0.demo.pp.plesk.ru 1 admin
5212 ppu12-0.demo.pp.plesk.ru 1 admin
 
Hello IgorG,

I have tried your approach, using mailbox_id to 1 in all lists, since I don't know what mailbox_id is.

It works so far for me, although I always get an enigmatic error: "Unable to parse string: <blank>"

I am trying another approach based on the database and the mn_param table.

SELECT mail.mail_name, domains.name, mn_param.val, mail.mbox_quota FROM mail, mn_param, domains WHERE mail.id=mn_param.mn_id AND mail.dom_id=domains.id AND mn_param.param='box_usage' and mail.mail_name="NAMEBEFORE@" and domains.name="DOMAIN"

I assume that this would also be equivalent.
 
You can find IDs of mailboxes with

mysql> select concat(mail.mail_name,"@",domains.name) as address, mail.id from mail,domains,accounts where mail.dom_id=domains.id and mail.account_id=accounts.id order by address;
 
I want to use the mailbox_usage command.
SQL can now look up mailbox IDs.
How do I actually use the mailbox_usage command?

For example, if I wanted to look up [email protected] and the ID of this email address was 10, would the command look like this?

# /usr/local/psa/admin/bin/mailbox_usage --in-block example.com 10 mailadd
 
How do I actually use the mailbox_usage command?
You have to run the command:

# /usr/local/psa/admin/bin/mailbox_usage --in-block

then type

example.com 10 mailadd

and get something like

2026868 example.com 10 mailadd

in output. More details in help:

# /usr/local/psa/admin/bin/mailbox_usage --help
Usage: mailbox_usage [--in-blocks]
STDIN should contain a set of '<domain_name> <mailbox_id> <mailbox_name>' strings
STDOUT will contain a set of '<counted_usage> <domain_name> <mailbox_id> <mailbox_name>' strings
 
Thanks IgorG!

I was able to get the value by the method you told me. Please tell me one more thing.
What value is returned by this command?
I want to get the mailbox utilization with the CLI, but I get the maximum value for each mailbox with the following command, and even though the mailbox is 100%, the values don't match.

A. /usr/local/psa/bin/mail -i [email protected] | grep 'Mbox quota'
If there is "Unlimited"
B. /usr/local/psa/bin/subscription_settings -i example.com | grep mbox_quota
(If the suffix is KB, multiply by 1024, suffix is MB, multiply 1024000...)

Is the way of thinking wrong?
English may be strange because I use machine translation. Sorry.
 
Back
Top