Author Topic: How to generate a list of all user and group mail aliases ?  (Read 2026 times)

anwarpp

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Hi -

I have a requirement to list out all valid email addresses on a Zentyal server from a shell script (or the command line in general).  I am able to get the list of valid users via "getent passwd" and list of all users via "getent group". And I am able to pick up whatever is in /etc/aliases. But I am unable to get the list of user and group mail aliases created from the Zentyal GUI.

How can we generate a list of all user and group mail aliases from a script (or the command line) ?

Thanks !

anwarpp

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to generate a list of all user and group mail aliases ?
« Reply #1 on: May 07, 2013, 05:15:02 am »
Seems like this gives me what I am looking for.

Code: [Select]
slapcat | grep "mail=" | cut -f2 -d'=' | sed 's/,ou//' |grep -v "^@.*"

christian

  • Guest
Re: How to generate a list of all user and group mail aliases ?
« Reply #2 on: May 07, 2013, 06:03:02 am »
well, it works but this might not be very efficient if you have a lot of entries.
I mean you're reading the whole directory then "grep"...
You have to know that such LDAP search is not very fast (although you might not be concerned with performance) but it also consumes resources server side.

The proper way, from ldap standpoint, is to use ldapsearch command. Furthermore, it will give you more flexibility to refine entries you want to take in account. (e.g. you may have entries with mail attribute that you don't want to keep in your list)

if goal is to search for all entries with mail address, then your ldap search filter would be:
(mail=*)

if goal is to tackle only users and groups, you may use
(&(mail=*)(|(objectclass=couriermailaccount)(objectclass=couriermailalias)))

notice that if searching for users only, you can refine your ldap search base to ou=users,dc=...
while if searching for groups too (in fact aliases), search base must cover both thus dc=...

You can store result in LDIF file of course.

One last comment: be sure that mail attribute is indexed. I don't know the current status but some time ago, default Zentyal deployment was not maintaining such index  :-\