[CentOS] [OT] List of all email users

mouss mouss at netoyen.net
Sun Nov 2 17:39:16 UTC 2008

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


   for file in $files; do
     sed -e '/^[\# 	]/d' -e '/^$/d' $file | \
       awk -F'[:         ]' '{print $1}'

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.

More information about the CentOS mailing list