This is not CentOS-specific, hence OT.
I need a list of all email users on my system (there are hundreds of them). The list could be extracted from /etc/aliases and the virtusertable.
Does anyone know of a script that would do this automatically? It would have to - exclude commented-out lines (of course) - exclude duplicates - produce a list of usernames (or maybe unresolved email addresses for some users) separated by a comma
I imagine perl would be the way to go. I haven't used perl at all myself.
Regards, Jussi
-- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi@greenspot.fi * http://www.greenspot.fi
Jussi Hirvi wrote:
This is not CentOS-specific, hence OT.
I need a list of all email users on my system (there are hundreds of them). The list could be extracted from /etc/aliases and the virtusertable.
Does anyone know of a script that would do this automatically? It would have to
- exclude commented-out lines (of course)
- exclude duplicates
- produce a list of usernames (or maybe unresolved email addresses for some
users) separated by a comma
for i in /etc/aliases /etc/postfix/virtual; do cat $i | grep -Ev "(^#|^\s+$|^$)" | sed -e "s/://" | awk '{print $1}' | \ sort -u | tr \n , done
Adapt to needs.
Ralph
Ralph Angenendt (ra+centos@br-online.de) kirjoitteli (30.10.2008 17:12):
for i in /etc/aliases /etc/postfix/virtual; do cat $i | grep -Ev "(^#|^\s+$|^$)" | sed -e "s/://" | awk '{print $1}' | \ sort -u | tr \n , done
Adapt to needs.
Thanks, that looks neat, and works.
For real-world use, I guess the source files (in my case aliases, virtusertable) should be prepared first - the list will include unwanted users like "bin" or "mysql", mailing list name defined in virtusertable, and possibly other strange things too.
- Jussi
-- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi@greenspot.fi * http://www.greenspot.fi
Jussi Hirvi wrote:
For real-world use, I guess the source files (in my case aliases, virtusertable) should be prepared first - the list will include unwanted users like "bin" or "mysql", mailing list name defined in virtusertable, and possibly other strange things too.
and what about the user accounts in /etc/passwd ?
John R Pierce (pierce@hogranch.com) kirjoitteli (30.10.2008 17:39):
and what about the user accounts in /etc/passwd ?
Hm, yes, never thought of that! That would be a very good (certainly easy) approach, though with its own limitations (it misses those users whose mail is forwarded in /etc/aliases to external addresses like gmail.com etc.).
- Jussi
-- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi@greenspot.fi * http://www.greenspot.fi
On Fri, Oct 31, 2008, Jussi Hirvi wrote:
John R Pierce (pierce@hogranch.com) kirjoitteli (30.10.2008 17:39):
and what about the user accounts in /etc/passwd ?
Hm, yes, never thought of that! That would be a very good (certainly easy) approach, though with its own limitations (it misses those users whose mail is forwarded in /etc/aliases to external addresses like gmail.com etc.).
I have a routine that pulls addresses from all the aliases files defined in the postfix main.cf file, and gets all non-admin accounts from /etc/passwd, combining the two to get all valid user names. It then gets all the domains from the postfix mydestination, combining the user names with these domains to build a large virtual file for a border MX server that has no users to allow it to validate incoming mail.
This have been working nicely for several years at an ISP with about 10,000 e-mail accounts. The border MX server does preliminary IP based anti-spam and uses amavisd and clamav to scan for phishing and worms that attack the Microsoft virus, Windows, but does no spam checking. It then sends messages that pass amavisd to a cluster of servers that do spamassassin checking, and delivery to NFS mounted Maildir stores.
Bill
Jussi Hirvi wrote:
Ralph Angenendt (ra+centos@br-online.de) kirjoitteli (30.10.2008 17:12):
for i in /etc/aliases /etc/postfix/virtual; do cat $i | grep -Ev "(^#|^\s+$|^$)" | sed -e "s/://" | awk '{print $1}' | \ sort -u | tr \n , done
Thanks, that looks neat, and works.
For real-world use, I guess the source files (in my case aliases, virtusertable) should be prepared first - the list will include unwanted users like "bin" or "mysql", mailing list name defined in virtusertable, and possibly other strange things too.
And (I forgot to say that) - it weeds out users with a ":" in their mail address, which is completely valid. So you should check that also.
Cheers,
Ralph
Jussi Hirvi wrote:
This is not CentOS-specific, hence OT.
I need a list of all email users on my system (there are hundreds of them). The list could be extracted from /etc/aliases and the virtusertable.
Does anyone know of a script that would do this automatically? It would have to
- exclude commented-out lines (of course)
and exclude "continuation" lines (lines starting with spaces).
- exclude duplicates
- produce a list of usernames (or maybe unresolved email addresses for some
users) separated by a comma
why comma? isn't LF better (one user per line)?
I imagine perl would be the way to go. I haven't used perl at all myself.
you could start with something like
getkey() { files=$*
for file in $files; do sed -e '/^[# ]/d' -e '/^$/d' $file | \ awk -F'[: ]' '{print $1}' done }
getkey /etc/aliases /etc/passwd | sort|uniq > users.local getkey yourvirtualmap > users.virtual
If you want a list of all valid email addresses, you need to append the domains in mydestination to users.local.
Thanks Mouss and others. I have now more than enough to get on with.
mouss (mouss@netoyen.net) kirjoitteli (2.11.2008 19:39):
why comma? isn't LF better (one user per line)?
LF or comma, it doesn't matter much. I said comma, because I am going to utilize the list to build one huge alias "my_email_customers". :-)
Regards, Jussi
-- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi@greenspot.fi * http://www.greenspot.fi
Jussi Hirvi wrote:
Thanks Mouss and others. I have now more than enough to get on with.
mouss (mouss@netoyen.net) kirjoitteli (2.11.2008 19:39):
why comma? isn't LF better (one user per line)?
LF or comma, it doesn't matter much. I said comma, because I am going to utilize the list to build one huge alias "my_email_customers". :-)
if the list is huge, you may run into problems. better use a mailing-list.
mouss wrote:
Jussi Hirvi wrote:
Thanks Mouss and others. I have now more than enough to get on with.
mouss (mouss@netoyen.net) kirjoitteli (2.11.2008 19:39):
why comma? isn't LF better (one user per line)?
LF or comma, it doesn't matter much. I said comma, because I am going to utilize the list to build one huge alias "my_email_customers". :-)
if the list is huge, you may run into problems. better use a mailing-list.
_And_ keep in mind that you are going to get replies and probably spam to this address. So you'll probably want to turn on the moderation feature of the list.
Les Mikesell (lesmikesell@gmail.com) kirjoitteli (3.11.2008 16:05):
_And_ keep in mind that you are going to get replies and probably spam to this address. So you'll probably want to turn on the moderation feature of the list.
Instead I keep that alias commented out except when I want to send information to the email users! That alias really would be a jackpot for the spammers. :-)
- Jussi
-- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi@greenspot.fi * http://www.greenspot.fi