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 at 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 commafor 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20081030/1c93568f/attachment-0003.sig>
Ralph Angenendt (ra+centos at 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 at 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)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 commawhy 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.