AFP548

LDAP Info Tab Auto-fill

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

<code>
shortname,street,city,state,zip,country,work tel,mobile tel,fax,pager,mail,mail2,mail3,aim,jabber,msn,icq,yahoo,url,blog
</code>

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:

<code>
...,andrina@example.com,none,none,...
</code>

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:
    <code>
    ./info_filler &#91;ldap_admin&#93; &#91;ldap_password&#93; &#91;ldap server&#93; &#91;path/to/csv_file&#93;
    </code>
  • 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:
    <code>
    DC_PART1="example"
    DC_PART2="com"
    </code>
  • 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.

    andrina

    Andrina Kelly is responsible for anything and everything touched by, or connected to, a Mac at Bell Media, Canada's premiere multimedia company. You may recognize her name from the end credits of Canada's evening news broadcast. She has previously spoken at MacSysAdmin, JAMF National Users Conference, Apple's WWDC, Macworld IT conferences, Mac Networkers Retreat, and Canada MacExpo.

    More Posts

  • Exit mobile version