Contribute  :  Advanced Search  :  Directory  :  Forum  :  FAQ's  :  My Downloads  :  Links  :  Polls  
AFP548 Changing the world one server at a time.
Welcome to AFP548
Thursday, July 29 2010 @ 09:28 am MDT
   

LDAP Info Tab Auto-fill

ArticlesThat info tab with all it's empty fields has been taunting me with all it's wonderful uses, but sitting down and filling in 500+ users with all their individual data is not something even I'd wish on my worst enemy!

Read On for details on how to have all the fields filled in 30 minutes or less...

The biggest issue I faced when starting working on this was figuring out where my data was coming from. So many people have this data already, but getting it into a format that will easily import into LDAP was the real challenge. Asking around, it seemed that spreadsheets and databases were the norm, both or which have some sort of function to export to a comma delimited file (csv), so this was my jumping off point.

Setting up your csv file is probably going to be the toughest part of this whole exercise, you have to put it in a specific order - otherwise you're going to end up with your users residing in their phone numbers... So, here's the order of the csv file:


shortname,street,city,state,zip,country,work tel,mobile tel,fax,pager,mail,mail2,mail3,aim,jabber,msn,icq,yahoo,url,blog
This is pretty close to the order found in the info tab now in Workgroup Manager. There are a couple caveats to this however, because the script is using ldapmodify to bring in all this data for us, it will result in an error and no data being imported if there are blanks left in your csv file. The other thing to note is that the mail addresses need to be distinct - for example, in my testing I had my 3 e-mail addresses as follows:

...,andrina@example.com,none,none,...
This didn't work as ldapmodify was seeing the two "none" addresses as the same entry. It's only the multiple e-mails this affects, the IM accounts are handled differently.

A little information on csv files: Check your csv in a very simple text editor before running with it, some applications have a habit of not creating line breaks correctly when exporting to csv - a simple test of this is simply viewing your csv file in the terminal - if you're seeing a lot of unrecognizable characters where you'd expect to see line breaks, you've created your csv with one of these applications. Drop your csv into vi, TextWrangler or even TextEdit, and do a find and replace on the fake line break and replace it with a real one.

Notes on actually running the script:

  • Try it out on a testing server first!
  • The script takes arguments at execution in the following manner:
    
    ./info_filler [ldap_admin] [ldap_password] [ldap server] [path/to/csv_file]
    
  • Make sure that you're passing the directory administrator username and password - this is the username and password you set up when you first promoted your server to an Open Directory Master.
  • The LDAP server argument is either the FQDN of your server, or it's IP adress - i.e. server.example.com
  • Change the settings within the script for your base DN and add more variables if required for your environment:
    
    DC_PART1="example"
    DC_PART2="com"
    
  • Be Patient! Depending on how many users you're filling in information for, this script could take a few moments to run, in my testing I found 5-8 minutes was reasonable for a couple hundred users.

    The script is available for download from our scripts archive here.

  • Story Options

    Advertising

    LDAP Info Tab Auto-fill | 8 comments | Create New Account
    The following comments are owned by whomever posted them. This site is not responsible for what they say.
    LDAP Info Tab Auto-fill
    Authored by: Anonymous on Monday, July 18 2005 @ 11:02 pm MDT
    Here's an enhancement for the sed/grep/awking you're doing to pull
    the last name out:

    grep 'cn:' | sed -e 's/cn\:\ //g' | sed -e 's/[0-9,(,)]//g' | awk '{print $2,
    $3}' | sed 's/[[:blank:]]*$//g'

    This will pull out any parentheses and numbers, but preserve two-name
    last names (Van Nelson, for example), while preserving the space
    between the two names and stripping any trailing spaces.
    • post a comment - Authored by: Anonymous on Saturday, July 30 2005 @ 11:58 am MDT
    LDAP Info Tab Auto-fill
    Authored by: dthompson on Friday, October 07 2005 @ 07:01 am MDT
    Curious to know if there is anyway just to import the first and last names and of
    the users into the info tab and ignore the rest of the information..

    Could I just comment out the rest of the information (street, email, phone, etc)?