Get member of Zimbra Distribution group command line

Get the members of a Zimbra distribution group from the command line. The admin console shows members too, but zmprov is quicker on a large server, easy to script, and works over SSH.

Prerequisites

  • Shell access to the Zimbra server (any version with zmprov, Zimbra 8 through 10).
  • The full address of the distribution list.

1. Switch to the zimbra user

To get the members of a distribution list in Zimbra, login, and su to the zimbra user. The Zimbra tools are on that account’s PATH, not root’s.

su - zimbra
Shell prompt as the zimbra user on the Zimbra server before running zmprov

2. Get the distribution list

Issue the following command. gdl is short for getDistributionList; it prints all of the list’s attributes followed by a members section, and piping to tail shows the end of the output where the members are.

zmprov gdl DistributionList@Domain.com | tail
zmprov gdl DistributionList@Domain.com | tail to show distribution list members

This should output a list of “members” at the end. If it’s a large distribution list, you may want to modify the | tail command like so:

zmprov gdl netflix@zwiegnet.com | tail -n 100
zmprov gdl netflix@zwiegnet.com | tail -n 100 for a large Zimbra distribution list

This will show the last 100 lines or so of the output, rather than the default last 10.

Print only the member addresses

Members are stored in the zimbraMailForwardingAddress attribute, so you can ask for just that attribute and skip the tail guesswork:

zmprov gdl netflix@zwiegnet.com zimbraMailForwardingAddress
zmprov gdl netflix@zwiegnet.com zimbraMailForwardingAddress | grep -c zimbraMailForwardingAddress

The second command counts the members.

Related commands

  • zmprov gadl lists every distribution list on the server.
  • zmprov gdlm user@domain.com shows which lists an account belongs to.
  • zmprov adlm list@domain.com user@domain.com and zmprov rdlm list@domain.com user@domain.com add and remove members.

Troubleshooting

  • zmprov: command not found: you are still root. Run su - zimbra first.
  • ERROR: account.NO_SUCH_DISTRIBUTION_LIST: the address is wrong or it is an alias; check the name with zmprov gadl | grep -i listname.
  • Output is slow: plain zmprov starts a new Java process each time. For many lookups, run zmprov -l (LDAP mode) or open an interactive zmprov session and type the commands there.

That’s it!

Related guides: Find out what version of Zimbra you are running | Restart Zimbra Community Services CentOS 6

Leave a Reply

Your email address will not be published. Required fields are marked *