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

closed as off-topic by masegaloeh, fukawi2, Andrew Schulman, mdpc, HopelessN00b Mar 8 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.

3 Answers 3

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.