LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-07-2008, 11:32 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
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?
 
Old 02-07-2008, 12:49 PM   #2
frndrfoe
Member
 
Registered: Jan 2008
Distribution: RHEL, CentOS, Ubuntu
Posts: 379

Rep: Reputation: 38
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.
 
Old 02-08-2008, 02:55 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 256Reputation: 256Reputation: 256
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.
 
Old 02-08-2008, 04:12 PM   #4
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
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...
 
Old 02-08-2008, 04:23 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 256Reputation: 256Reputation: 256
Quote:
Originally Posted by Carlwill View Post
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.
 
Old 02-08-2008, 04:31 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 256Reputation: 256Reputation: 256
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.
 
Old 02-08-2008, 04:31 PM   #7
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
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
 
Old 02-08-2008, 04:38 PM   #8
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 256Reputation: 256Reputation: 256
Quote:
Originally Posted by Carlwill View Post
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:13roxy:/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:107ovecot 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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Postfix virtual mailboxes + Courier POP3 Child of Wonder Linux - Software 2 08-04-2006 07:44 AM
Creating new mailboxes in Postfix+Cyrus IMAP+Saslauthd gugabaga Linux - Networking 4 05-10-2006 09:02 PM
Postfix multiple domains & mailboxes fatum112 Linux - Software 0 11-21-2005 01:13 PM
Postfix - track mail or browse mailboxes czezz Linux - Networking 3 07-19-2005 03:33 PM
mail filtering with Postfix and virtual mailboxes pembo13 Linux - Networking 2 09-17-2004 07:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration