LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Counting Mailboxes on Postfix? (https://www.linuxquestions.org/questions/linux-server-73/counting-mailboxes-on-postfix-619376/)

carlosinfl 02-07-2008 11:32 AM

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?

frndrfoe 02-07-2008 12:49 PM

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.

trickykid 02-08-2008 02:55 PM

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.

carlosinfl 02-08-2008 04:12 PM

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...

trickykid 02-08-2008 04:23 PM

Quote:

Originally Posted by Carlwill (Post 3050798)
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...

Well, most systems will have UID 0 - 99 reserved as system users and not actual logins. So you can get a list of all the users perhaps with a UID with 3 or more numbers in it, but this might not be accurate, some programs that need to create user accounts will go to the next available number and so on.

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.

trickykid 02-08-2008 04:31 PM

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.

carlosinfl 02-08-2008 04:31 PM

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
11


trickykid 02-08-2008 04:38 PM

Quote:

Originally Posted by Carlwill (Post 3050817)
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
11


Yeah, looking at your list of users, like mentioned, every system is different. You have nobody with a UID above 99, along with postfix and a few others. That's why your count is above 2. Might need to go with the shadow file to grab actual users with a password to the system, that should eliminate the system users that don't have passwords and not used as regular shell/email type accounts.


All times are GMT -5. The time now is 04:48 PM.