Sun Directory Services 3.1 Administration Guide

Example: Using dsimport

This example describes how to create a mapping file, and use dsimport to perform a bulk load of information stored in a text file.

Input File

The file containing the information to import into the LDAP directory could be an extract from a corporate online directory service that provides basic information about employees.

This file is shown in Example 5-1.


Example 5-1 Example of Input File

Rob Green, rgreen@london.XYZ.com, phone x 44 1234, marketing communications
manager
Jean White, jwhite@london.XYZ.com, phone x44 1123, documentation manager
Susan Brown, sbrown@london, phone (44) 123 45 67 00, technical writer
Karen Gray, kgray@london, tel (44) 123 45 67 01, engineering project manager
Steve Black, sblack@eng, x44 1122, software development engineer
Felipe Diaz Gonzalez, fdgonzalez@eng, x41 2233, software development
engineer
Anne Marie de la Victoire, amvictoire@paris.xyz.com, x33 3344, software
support engineer
DURAND Pierre, pdurand@paris, tel 33 1133, software support engineer

In this file, there is one employee definition per line. On each line the information is ordered as follows:

The level of information is not always consistent for the various employees: the e-mail address is not always fully qualified, the telephone number is not always a complete telephone number but an extension, and in one case the last name is given before the first name.

If you want a consistent level of information for the entries that will be created in the LDAP directory, you must either make the necessary corrections in the source file, or make them after the import operation using the Deja tool.

Mapping File

The intention of the directory administrator is to create all employee entries under the naming context ou=People, o=XYZ, c=US. The token that specifies this in the mapping file is the BASE_DN token in the Common section.

The information will be imported just once. Therefore, it is not necessary to define an Export section in the mapping file. The Dynamic section is mandatory. The object class definition in the Condense section is also mandatory.

The mapping file created by the directory administrator is shown in Table 5-2.

Table 5-2 Example of Mapping File
# This example file for dsimport contains employee entries
# to be created as inetOrgPerson objects,in the LDAP directory.

Front-End: EXAMPLE

Table: People

	Common:
		BASE_DN=ou=People, o=XYZ, c=US

	Dynamic:
		LINE => $cn, $rest
		MATCH_FILTER=(&(objectClass=inetOrgPerson)(cn=$cn))
		ALL_FILTER=(&(objectClass=inetOrgPerson)(cn=*))

	Import:
		Extract:
			LINE => $fn $ln, $mail, $telephoneNumber, $description
		Condense:
			cn=$fn $ln
			snT=$ln
			objectClassT=string2instances("top person
organizationalPerson inetOrgPerson", " ")
		Build:
			dn=cn=$cn, $BASE_DN
			sn=$snT
			mail=$mail
			telephoneNumber=$telephoneNumber
			description=$description
			objectClass=$objectClassT

The Condense section contains the inheritance tree for the inetOrgPerson object class.

The Build section contains all the mandatory attributes pertaining to or inherited by the inetOrgPerson object class. It also contains the optional attributes pertaining to this object class that the directory administrator required.

Running dsimport

To import the file described in "Input File" sing the mapping file described in "Mapping File", you can use dsimport with the following arguments:

# dsimport -h hostname -D cn=admin,o=xyz,c=us -w secret -m mapping.file
-f EXAMPLE -t People input.file

where:

It is not strictly necessary to specify the DN and password of the administrator on the command line. If you omit these parameters, dsimport will read them from the dsserv.conf file. The advantage is that the DN and password of the administrator will not be displayed by the ps command.

After running this command, the following message is displayed:

Lines read: 9, processed: 8  Entries: added 10, modified 0, deleted 0, errors 0

The line count includes blank lines. The number of entries created is greater than the number of lines in the file because the dsimport command automatically creates the root entry, in this example o=xyz, c=US.