Results 1 to 4 of 4

Thread: problems with scipt to copy ad to zimbra

  1. #1
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    3

    Default problems with scipt to copy ad to zimbra

    Hey guys i am trying to run the following script:
    Code:
    #!/bin/bash
    # zsync_ad.sh is a script thant syncs AD users and Zimbra users
    # It is unidirectional, just replicates changes from AD to ZCS
    # Developed on 20081006 by Eduardo Gonzalez <egrueda@gmail.com> 
    # Testing version 0.6 - Use at your own risk
    
    LDAPSEARCH=/usr/bin/ldapsearch
    ZMPROV=/opt/zimbra/bin/zmprov
    DOMAIN_NAME="injjdowns.com"
    TIMESTAMP=`date +%N`
    TMP_DIR=/tmp
    ADS_TMP=$TMP_DIR/users_ads_$TIMESTAMP.lst
    ZCS_TMP=$TMP_DIR/users_zcs_$TIMESTAMP.lst
    DIF_TMP=$TMP_DIR/users_dif_$TIMESTAMP.lst
    
    # Server values
    LDAP_SERVER="ldap://10.0.5.30"
    BASEDN="dc=injjdowns,dc=com"
    BINDDN="CN=Dani Cela,CN=Users,DC=injjdowns,DC=com"
    BINDPW="SECRET"
    FILTER="(&(sAMAccountName=*)(objectClass=user)(givenName=*))"
    FIELDS="mail"
    
    # Extract users from ADS
    echo -n "Quering ADS... "
    $LDAPSEARCH -x -H $LDAP_SERVER -b $BASEDN -D "$BINDDN" -w $BINDPW "$FILTER" $FIELDS | \
      grep "@$DOMAIN_NAME" | \
      awk '{print $2}' | \
      sort > $ADS_TMP
    echo "Found `cat $ADS_TMP | wc -l` users ($ADS_TMP)"
    
    # Extract users from ZCS
    echo -n "Quering ZCS... "
    $ZMPROV -l $DOMAIN_NAME > $ZCS_TMP
    echo "Found `cat $ZCS_TMP | wc -l` users ($ZCS_TMP)"
    
    # Generate diff
    echo "Generating diff file ($DIF_TMP)"
    diff -u $ZCS_TMP $ADS_TMP | grep "$DOMAIN_NAME" > $DIF_TMP
    
    # Clean up users list
    rm -f $ADS_TMP $ZCS_TMP
    
    # Import new users
    echo -n "New users: "
    cat $DIF_TMP | grep ^+ | wc -l
    for i in $(cat $DIF_TMP | grep ^+ | sed s/^+//g);
    do
      echo -n " - Adding $i ";
      $ZMPROV createAccount $i passwd > /dev/null;
      RES=$?
      if [ "$RES" == "0" ]; then echo "[Ok]"; else echo "[Err]"; fi
    done
    
    # Delete old users
    echo -n "Old users: "
    cat $DIF_TMP | grep ^- | wc -l
    for i in $(cat $DIF_TMP | grep ^- | sed s/^-//g);
    do
      echo -n " - Deleting $i ";
      $ZMPROV deleteAccount $i > /dev/null;
      RES=$?
      if [ "$RES" == "0" ]; then echo "[Ok]"; else echo "[Err]"; fi
    done
    
    
    # Clean up diff list
    #rm -f $DIF_TMP
    The output i get is the following:

    Code:
    zimbra@JJDZCS01:~$ /opt/zimbra/zsync_ad.sh 
    Quering ADS... Found 0 users (/tmp/users_ads_800087391.lst)
    Quering ZCS... ^CFound 0 users (/tmp/users_zcs_800087391.lst)
    Generating diff file (/tmp/users_dif_800087391.lst)
    New users: 0
    Old users: 0
    What i cant figure out is why it is finding no users?

    If i run the following script separately

    Code:
    ldapsearch -x -H ldap://10.0.5.30 -b "dc=injjdowns,dc=com" -D "CN=Dani Cela,CN=Users,DC=injjdowns,DC=com" -w SECRET "(&(sAMAccountName=*)(objectClass=user)(givenName=*))"
    The output i get is all of my users

    Can anyone assist with this?

    Thanks,

    Dani C

  2. #2
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    do all your users in AD have hte email field filled out?

  3. #3
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    3

    Default

    Quote Originally Posted by bdial View Post
    do all your users in AD have hte email field filled out?
    No they do not.

  4. #4
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    i think thats your issue. the script returns the mail field for the users that match the search, and uses that as the zimbra account.

Similar Threads

  1. Copy password from AD to Zimbra
    By datnus in forum Migration
    Replies: 4
    Last Post: 11-30-2011, 06:06 PM
  2. scipt to always download the latest connector?
    By dave_kempe in forum Administrators
    Replies: 0
    Last Post: 08-31-2011, 10:06 PM
  3. Replies: 0
    Last Post: 01-11-2011, 11:10 AM
  4. Zimbra Mail copy to another Server
    By ayush1440 in forum Administrators
    Replies: 6
    Last Post: 07-14-2010, 03:57 AM
  5. Replies: 5
    Last Post: 09-09-2008, 06:51 PM

Posting Permissions

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