Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find the total number of email accounts in a cPanel Linux server.

This must include only the active accounts. i.e. only those accounts whose MX is pointing to this server.

share|improve this question

closed as off-topic by masegaloeh, fukawi2, Andrew Schulman, mdpc, HopelessN00b Mar 8 '15 at 3:38

This question appears to be off-topic. The users who voted to close gave these specific reasons:

If this question can be reworded to fit the rules in the help center, please edit the question.

You can do it using following one liner.

for i in `cat /etc/localdomains`; do grep -E ^$i: /etc/userdomains ; done | sed 's/://g' | awk '{ system("cat /home/"$2"/etc/"$1"/passwd") }' 2>/dev/null | wc -l
share|improve this answer
Thanks, this was what I was looking for :) – Ajo Augustine Mar 29 '11 at 5:55

I have tried this script which checks the users in '/etc/userdomains' and displays the count of total mail accounts in the server.

sed "s|:||g" /etc/userdomains | awk '!/^\* nobody/{print $1, $2 | "sort | uniq" }' | awk '{print "cat /home/"$2"/etc/"$1"/passwd"}' | sh 2>/dev/null | wc -l

but I am looking for a script which could search the /etc/localdomains.

Regards, Ajo

share|improve this answer

You can try this too:

find /home*/*/etc -name passwd -exec cat {} \; | wc -l
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.