[SOLVED] Listing Distribution List Members

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Post Reply
rwjblue
Posts: 29
Joined: Fri Sep 12, 2014 9:56 pm

[SOLVED] Listing Distribution List Members

Post by rwjblue »

We have been using the distribution lists feature via the Admin UI for a while now, and we keep finding more and more uses for them. The only problem that we have come across (caused by us) is that we need to periodically audit the members of each distribution list. We do this to make sure that all required users are on each list, and that no one is on a list that they shouldn't be.
I did not see anything already available that did this so I put together a real basic LDAP query to accomplish this task. I figured that if I needed to do this someone else would also, so here is the basic query to list the members of all distribution lists:


ldapsearch -x -v -H 'ldap://localhost/' -b 'ou=people,dc=mydomain,dc=com' "objectClass=zimbraDistributionList" mail zimbraMailForwardingAddress


If you only want to list a single distribution list you can run the query as follows:


ldapsearch -x -v -H 'ldap://localhost/' -b 'uid=distributionlistname,ou=people,dc=mydomain,dc=com' "objectClass=zimbraDistributionList" mail zimbraMailForwardingAddress


These commands need to be run as the zimbra user. Also, make sure you replace these strings:

mydomain - should be your domain name

distributionlistname - should be the name of the distribution list you are trying to list
Hopefully, someone else will get some use out of this.
RobertJ
mmorse
Ambassador
Ambassador
Posts: 6036
Joined: Fri Sep 12, 2014 10:24 pm

[SOLVED] Listing Distribution List Members

Post by mmorse »

Simpler would be to :

su zimbra

zmprov gdl list@domain.com



If you forget the list names:

zmprov gadl (or zmprov gadl domain.com)
glitch23
Advanced member
Advanced member
Posts: 121
Joined: Fri Sep 12, 2014 10:14 pm

[SOLVED] Listing Distribution List Members

Post by glitch23 »

Funny enough I prefer the ldap search query over the zmprov's method since usually the people who ask for such information do not need to know all the information the it provides.
zmprov gadl > /tmp/distlist.tmp

for list in `cat /tmp/distlist.tmp`; do

zmprov gdl $list > /home/zimbra/temp/$list;

done
Which will give you a directory full of text files for each distribution list.
Which I might now modify with the ldap queries.
11444Mindaugas
Posts: 28
Joined: Sat Sep 13, 2014 1:24 am

[SOLVED] Listing Distribution List Members

Post by 11444Mindaugas »

Hello,

glitch23 I have ran your script but getting an error:

"ambiguous redirect".
Maybe you know how to solve it?
Thank You
phoenix
Ambassador
Ambassador
Posts: 27278
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

[SOLVED] Listing Distribution List Members

Post by phoenix »

[quote user="11444Mindaugas"]Maybe you know how to solve it?[/QUOTE]How about one of these: site:zimbra.com +"ambiguous redirect" - Yahoo! Search Results
If that doesn't work an internet search for the error message should find an answer.
Regards

Bill

Rspamd: A high performance spamassassin replacement

Per ardua ad astra
glitch23
Advanced member
Advanced member
Posts: 121
Joined: Fri Sep 12, 2014 10:14 pm

[SOLVED] Listing Distribution List Members

Post by glitch23 »

[quote user="11444Mindaugas"]Hello,

glitch23 I have ran your script but getting an error:

"ambiguous redirect".
Maybe you know how to solve it?
Thank You[/QUOTE]
Make sure you use back ticks(sp?) " ` " versus apostrophes " ' "
for list in 'cat /tmp/distlist.tmp'; do (This will give you an error)

...

for list in `cat /tmp/distlist.tmp`; do (This will not)
11444Mindaugas
Posts: 28
Joined: Sat Sep 13, 2014 1:24 am

[SOLVED] Listing Distribution List Members

Post by 11444Mindaugas »

Thank you very much.
adiazm
Posts: 6
Joined: Fri Sep 12, 2014 11:39 pm

[SOLVED] Listing Distribution List Members

Post by adiazm »

I made this:
for lista in `zmprov gadl`; do

echo -e "$lista
" >> /tmp/listmembers.txt
for usuario in `zmprov gdl $lista | grep zimbraMailForwardingAddress | cut -d" " -f2`; do

member=`zmprov ga $usuario | grep displayName | cut -d: -f2`

echo -e "$usuario $member" >> /tmp/listmembers.txt

done

echo -e "----------

" >> /tmp/listmembers.txt

done
It creates a file (/tmp/listmembers.txt) in a very readable format.
Regards
minhhoang
Posts: 28
Joined: Sat Sep 13, 2014 3:14 am

[SOLVED] Listing Distribution List Members

Post by minhhoang »

Thank for sharing this. Could you please let me know how to import all distribution lists and members to new zimbra server using shell script?
Post Reply