How can I get a list of all "account alias" ?

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
2337Shadow
Posts: 6
Joined: Fri Sep 12, 2014 10:00 pm

How can I get a list of all "account alias" ?

Postby 2337Shadow » Mon Jan 15, 2007 7:07 am

Hi,
I need to list all "valid" accounts on my box. I can get my "distribution lists" using "zmprov gadl" and can get my "account" using "zmprov gaa". But, "zmprov gaa" don't return the "account alias", how can I get a list of the "account alias" ?


keithop
Advanced member
Advanced member
Posts: 59
Joined: Fri Sep 12, 2014 10:06 pm

How can I get a list of all "account alias" ?

Postby keithop » Sat Jun 16, 2007 8:13 am

I'd be interested in finding this too :/ did you ever get an answer or does anyone know?
phoenix
Ambassador
Ambassador
Posts: 26285
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

How can I get a list of all "account alias" ?

Postby phoenix » Sat Jun 16, 2007 9:10 am

A search of the forums would have found it for you:
zmprov ga address@domain | grep Alias
Regards

Bill

Rspamd: A high performance spamassassin replacement

If you'd like to see this implemented in a future version of ZCS then please vote on Bugzilla entries 97706 & 108168
qhartman
Posts: 3
Joined: Fri Sep 12, 2014 11:35 pm

How can I get a list of all "account alias" ?

Postby qhartman » Tue Jan 20, 2009 1:36 pm

Kind of a dead thread, but this seemed like a good place to document a quick hack I put together that retrieves all accounts in a zimbra instance and then lists all of the aliases associated with that account. As the Zimbra user:
for i in `zmprov gaa`; do echo ""; echo "$i:"; zmprov ga $i | grep MailAlias; done > acounts.txt

"accounts.txt" will then contain the list of accounts in a nice readable format.
Hope this helps somebody.
PhilF
Posts: 20
Joined: Fri Sep 12, 2014 10:28 pm

How can I get a list of all "account alias" ?

Postby PhilF » Tue Jan 20, 2009 10:04 pm

As long as we're adding to this thread -- here are another couple of ways to get a list of accounts and their aliases.
They should be faster than the previously mentioned program, since they employ a single zmprov command instead of spawing a new program to check each mailbox. The overhead of the latter can be huge on large systems. I created these when I was looking for a command-line way to list the aliases of my distribution lists. That seems to be missing from the zmprov inventory.


For folks who like basic Unix scripts, here's the first one I wrote:
DOMAIN=mydomain.com
zmprov sa -v zimbraMailDeliveryAddress="*@$DOMAIN"

| egrep '^(# name |cn:|zimbraMailAlias|$)'

| cat -s

| sed 's/^zimbraMailAlias:/ /; s/^# name /Mailbox: /; s/^cn: /Name: /'



The last two lines (and the trailing backslash at the end of the second line) aren't really necessary; they just pretty up the output a bit.
The third line (cat -s) will remove extra blank lines; you can get a lot of these if your users have mail filters. This command will work on many systems, but not all. If your system doesn't have "cat -s" you can get the same functionality with a one-line awk or perl script.
The fourth line (sed) cleans up the labels.
I actually prefer to do all of this in Perl; it's simpler, more flexible, and probably faster. Here's what I now run:
#

# aliasList: Lists all aliases for mailboxes and distribution lists associated with a particular domain

#

# Syntax: aliasList someMailDomain.com

#

#

# The settings for the LDAP queries are guesses. They work for me, but if I have overlooked

# something, please let me know!

# --

# Phil Freed

#

########
DOMAIN="$1"

OUTFILE="$DOMAIN.alias"
if [ -z "$DOMAIN" ]; then

echo

echo "ERROR!"

echo "Syntax: `basename $0` yourMailDomain.com"

echo

exit 2

fi


(

echo Listing mailbox aliases.... >&2

echo

echo "==================== Mailbox Aliases for $DOMAIN ========================"

echo
zmprov sa -v zimbraMailDeliveryAddress="*@$DOMAIN" | perl -ne

'

if ( s/^# name /
Mailbox: / or

s/^cn: /Name: / or

s/^zimbraMailAlias:/ / ) { print $_; }

'
echo Listing distribution list aliases.... >&2

echo

echo

echo "==================== Distribution List Aliases for $DOMAIN ========================"

echo
zmprov sa -v "(&(objectClass=zimbraDistributionList)(mail=*@$DOMAIN))" | perl -ne

'

if ( s/^# distributionList /
MailingList: / or

s/^cn: /Name: / or

s/^zimbraMailAlias:/ / ) { print $_; }

'

) > $OUTFILE
echo

echo " -- The list of aliases is now stored in '$OUTFILE'"

echo
sdrury
Advanced member
Advanced member
Posts: 163
Joined: Fri Sep 12, 2014 11:42 pm

How can I get a list of all "account alias" ?

Postby sdrury » Tue Jan 27, 2009 5:45 pm

Rather than running a script, is there a command like the zmprov ga user@domain | grep Alias that will list ALL aliases? I need to provide a list but not sure how to create and run the script examples above.
sdrury
Advanced member
Advanced member
Posts: 163
Joined: Fri Sep 12, 2014 11:42 pm

How can I get a list of all "account alias" ?

Postby sdrury » Tue Jan 27, 2009 5:46 pm

[quote user="qhartman"]Kind of a dead thread, but this seemed like a good place to document a quick hack I put together that retrieves all accounts in a zimbra instance and then lists all of the aliases associated with that account. As the Zimbra user:
for i in `zmprov gaa`; do echo ""; echo "$i:"; zmprov ga $i | grep MailAlias; done > acounts.txt

"accounts.txt" will then contain the list of accounts in a nice readable format.
Hope this helps somebody.[/QUOTE]
Tried to run this but got a permission denied message (yes running as zimbra user).
bdial
Elite member
Elite member
Posts: 1633
Joined: Fri Sep 12, 2014 10:39 pm

How can I get a list of all "account alias" ?

Postby bdial » Tue Jan 27, 2009 7:21 pm

i believe by default the zimbra user doesn't have write access to /opt/zimbra, which is probably the diretory yyou're trying to run that in. so it can't create the acounts file. i make a /opt/zimbra/scripts dir for mine and chown it to the zimbra user. run the script from there
PhilF
Posts: 20
Joined: Fri Sep 12, 2014 10:28 pm

How can I get a list of all "account alias" ?

Postby PhilF » Fri Jan 30, 2009 8:16 am

[quote user="sdrury"]Rather than running a script, is there a command like the zmprov ga user@domain | grep Alias that will list ALL aliases? I need to provide a list but not sure how to create and run the script examples above.[/QUOTE]
The first script in my previous post will work stand-alone; you can cut and paste it right into your terminal window. Just change the first line (DOMAIN=...) to the domain for which you want to view aliases. The script is really a one-liner, but it's been broken into multiple lines (each with a trailing backslash) to improve readability.


DOMAIN=mydomain.com
zmprov sa -v zimbraMailDeliveryAddress="*@$DOMAIN"

| egrep '^(# name |cn:|zimbraMailAlias|$)'

| cat -s

| sed 's/^zimbraMailAlias:/ /; s/^# name /Mailbox: /; s/^cn: /Name: /'



If you want all aliases, regardless of domain, you can do it this way (note that DOMAIN is no longer used):
zmprov  sa  -v objectClass="zimbraAccount" 

| egrep '^(# name |cn:|zimbraMailAlias|$)'

| cat -s

| sed 's/^zimbraMailAlias:/ /; s/^# name /Mailbox: /; s/^cn: /Name: /'


These two scripts will display all mailbox aliases. If you are one of those rare individuals that uses aliases for mailing lists, it won't show them. I can craft a "one-liner" that includes these as well, but I'll have to do it later. (I'm late for a meeting.) At the same time I'll talk a bit about how to set up and run a script. It's awfully handy to be able to do that.
PhilF
Posts: 20
Joined: Fri Sep 12, 2014 10:28 pm

How can I get a list of all "account alias" ?

Postby PhilF » Sat Jan 31, 2009 2:30 pm

Okay -- here's a one-liner that will find all aliases (including both mailboxes and distribution lists. The results will be put into /tmp/alias.list.


zmprov  sa  -v '(|(objectClass=zimbraDistributionList)(objectClass=zimbraAccount))' 

| egrep '^(# name |# distributionList|zimbraMailAlias)'

| cat -s

| sed 's/^zimbraMailAlias:/ /; s/^# name /
Mailbox: /; s/^cn: /Name: /; s/^# distributionList /
MailingList: /' > /tmp/alias.list




But (as they say in Perl-land), there's more than one way to do it. Here's another, which separates the mailbox aliases from the distribution list aliases. It's long, but you can just copy and paste it into your terminal window:
(

echo Listing mailbox aliases.... >&2

echo

echo "==================== Mailbox Aliases ========================"

echo
zmprov sa -v '(objectClass=zimbraAccount)' | perl -ne

'

if ( s/^# name /
Mailbox: / or

s/^cn: /Name: / or

s/^zimbraMailAlias:/ / ) { print $_; }

'
echo Listing distribution list aliases.... >&2

echo

echo

echo "==================== Distribution List Aliases ========================"

echo
zmprov sa -v "(objectClass=zimbraDistributionList)" | perl -ne

'

if ( s/^# distributionList /
MailingList: / or

s/^cn: /Name: / or

s/^zimbraMailAlias:/ / ) { print $_; }

'

) > /tmp/alias.list
echo

echo " -- The list of aliases is now stored in /tmp/alias.list"

echo

As for scripts -- they are nothing more than a collection of lines that you could easily type in (or paste in) on the command line. The handy thing about a script is that you don't have to re-type the commands each time. Here are some really basic directions in how to create a script; I apologize if I'm telling you things you already know. (I'm not trying to talk down, I'm just trying to be thorough.) For more -- and undoubtedly better -- examples, try googling "unix shell script tutorial".


First make a directory to store your scripts.

mkdir /opt/zimbra/scripts


Note that you only have to create a directory once, not each time you're going to make a script.
Now, change to that directory:

cd /opt/zimbra/scripts

Next step will be to create a file to hold your commands:

cat > listAlias

From this point on, anything you type will go into the file listAlias. So your next step should be to paste in one of the scripts you've found here. When that's done, hit to make sure you're at the beginning of a line, and then hit (which means to hold down the CTRL key, press the letter D, and then release them both).
You have now created a script file, but you need to tell Unix that it's OK to run the thing:

chmod +x listAlias

Now, each time you want to run the command, just type

/opt/zimbra/scripts/listAlias

You'll probably need to edit this file sometime. If you're not familiar with the Unix editor "vi", I recommend you google for "vi editor tutorial".
I hope that this is marginally helpful. If not, well... This week only I'm offering a double-your-money-back guarantee.
Take care, and good luck.

Return to “Administrators”

Who is online

Users browsing this forum: No registered users and 5 guests