Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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