Page 1 of 2 12 LastLast
Results 1 to 10 of 14

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

  1. #1
    Shadow's Avatar
    Shadow is offline Junior Member
    Join Date
    Nov 2005
    Location
    Maringá, Paraná, Brasil
    Posts
    8
    Rep Power
    9

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

    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" ?

  2. #2
    keithop is offline Senior Member
    Join Date
    Feb 2006
    Posts
    61
    Rep Power
    9

    Default

    I'd be interested in finding this too :/ did you ever get an answer or does anyone know?

  3. #3
    phoenix is offline Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,566
    Rep Power
    57

    Default

    A search of the forums would have found it for you:

    Code:
    zmprov ga address@domain | grep Alias
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  4. #4
    qhartman is offline New Member
    Join Date
    Jun 2008
    Posts
    3
    Rep Power
    7

    Default

    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:

    Code:
    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.

  5. #5
    PhilF is offline Intermediate Member
    Join Date
    Mar 2007
    Posts
    20
    Rep Power
    8

    Default

    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:

    Code:
    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:

    Code:
    #
    # 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 <url-zimbra@freed.com>
    #
    ########
    
    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 /\nMailbox: /  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 /\nMailingList: /  or
                s/^cn: /Name: /        or
                s/^zimbraMailAlias:/    / ) { print $_; }
         '
    ) > $OUTFILE
    
    echo
    echo " -- The list of aliases is now stored in '$OUTFILE'"
    echo

  6. #6
    sdrury is offline Special Member
    Join Date
    Aug 2008
    Location
    Brisbane, Australia
    Posts
    168
    Rep Power
    7

    Default

    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.

  7. #7
    sdrury is offline Special Member
    Join Date
    Aug 2008
    Location
    Brisbane, Australia
    Posts
    168
    Rep Power
    7

    Default

    Quote Originally Posted by qhartman View Post
    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:

    Code:
    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.
    Tried to run this but got a permission denied message (yes running as zimbra user).

  8. #8
    bdial's Avatar
    bdial is offline Moderator
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    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

  9. #9
    PhilF is offline Intermediate Member
    Join Date
    Mar 2007
    Posts
    20
    Rep Power
    8

    Default

    Quote Originally Posted by sdrury View Post
    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.
    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.


    Code:
    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):

    Code:
    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.

  10. #10
    PhilF is offline Intermediate Member
    Join Date
    Mar 2007
    Posts
    20
    Rep Power
    8

    Default

    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.


    Code:
    zmprov  sa  -v '(|(objectClass=zimbraDistributionList)(objectClass=zimbraAccount))' \
        | egrep '^(# name |# distributionList|zimbraMailAlias)' \
        | cat -s  \
        | sed 's/^zimbraMailAlias:/     /; s/^# name /\nMailbox: /; s/^cn: /Name: /; s/^# distributionList /\nMailingList: /' > /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:

    Code:
    (
      echo Listing mailbox aliases....  >&2
      echo
      echo "==================== Mailbox Aliases ========================"
      echo
    
      zmprov sa -v '(objectClass=zimbraAccount)' | perl -ne \
         '
           if ( s/^# name /\nMailbox: /  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 /\nMailingList: /  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.
    Code:
    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:
    Code:
    cd /opt/zimbra/scripts
    Next step will be to create a file to hold your commands:
    Code:
    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 <Enter> to make sure you're at the beginning of a line, and then hit <CTRL-D> (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:
    Code:
    chmod +x listAlias
    Now, each time you want to run the command, just type
    Code:
    /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.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reply To for Distribution List
    By alivebyscience in forum Administrators
    Replies: 3
    Last Post: 10-28-2006, 10:35 AM
  2. Orphaned alias for a distribution list
    By area in forum Administrators
    Replies: 0
    Last Post: 09-17-2006, 08:22 PM
  3. Replies: 1
    Last Post: 05-24-2006, 11:22 AM
  4. Distribution list problem
    By achow in forum Users
    Replies: 1
    Last Post: 05-15-2006, 08:45 PM
  5. Reading attachments problem
    By lenjacobs in forum Users
    Replies: 2
    Last Post: 12-27-2005, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •