Counting Mailboxes on Postfix?
I am running Postfix 2.2.10 and have the Maildir setup. I was wondering how someone would determine how many mailboxes are running on my server?
I can cd /home and see all of them but is there a way to count all the mailboxes being managed by Postfix? |
When the mail server gets a message it just checks to see if it has such a user and if there is a place to put the mail so the mail server really has no idea of how many users it has except for the one that it is dealing with currently.
I think the only way to know would be to count mailboxes like 'locate Maildir | wc -l' or something. |
Or if the users are authenticated from the passwd/shadow files on the system and aren't virtual users, you could get your information there. Everyone might not be using email but that would be the most accurate count of mailboxes that Postfix is currently or potentially handling.
|
Yes - all users are authenticated from /etc/passwd however I really am not sure what the command would be to get an accurate count from the passwd file...
|
Quote:
But something like this might work: cat /etc/passwd | cut -d":" -f3 | grep '[0-9][0-9][0-9]' | wc -l That uses some of the basic commands available without having to come up with any type of shell script or using awk, etc. But you might want to double check to make sure no system users that aren't users have a UID higher than 99, etc. Every system is different though. Another way to verify is if the user has a valid shell account that specified in the passwd file or possibly use the shadow file and go against if the user has an encrypted password. Most system users will not have any type of password configured, if they do, slap yourself. Only root will have a password usually since it's always UID 0. |
If you wanted to take the same type of approach I made earlier, you could do something like this on the shadow file to only pick those with actual passwords on the system which indicates they are real users and not system users:
cat /etc/shadow | cut -d":" -f2 | grep '....' | wc -l cats the shadow file, pipes output thru cut that grabs the field delimited by a colon which makes it field 2 where the hash for the password resides, then grep checks to see if it has more than 4 characters in the string, which I'd hope all passwords hashes are longer than that. Then the wc -l gets the total count. |
Thanks - I tested it on my home email server which only has two shell users which also have mailboxes on postfix.
root:x:1:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh www-data:x:33:33:www-data:/var/www:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh list:x:38:38:Mailing List Manager:/var/list:/bin/sh irc:x:39:39:ircd:/var/run/ircd:/bin/sh gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh nobody:x:65534:65534:nobody:/nonexistent:/bin/sh Debian-exim:x:100:102::/var/spool/exim4:/bin/false statd:x:101:65534::/var/lib/nfs:/bin/false identd:x:102:65534::/var/run/identd:/bin/false carlos:x:1000:1000:Carlos Williams,,,:/home/carlos:/bin/bash sam:x:1001:1001:Sam Williams,,,:/home/sam:/bin/bash postfix:x:103:105::/var/spool/postfix:/bin/false sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin dovecot:x:105:107:Dovecot mail server,,,:/usr/lib/dovecot:/bin/false spamd:x:5001:5001::/var/lib/spamassassin:/bin/nologin ntp:x:106:108::/home/ntp:/bin/false I ran the command & received the following: Code:
swordfish:~# cat /etc/passwd | cut -d":" -f3 | grep '[0-9][0-9][0-9]' | wc -l |
Quote:
|
All times are GMT -5. The time now is 10:57 PM. |