Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a reasonably large set of data in an LDAP server. Some of the attributes appear in many places, and I would like to replace them.

The data is not enormous, but it is enough to rule out editing and export manually.

What's the best approach for this? Use an LDAP tool to find and replace them? Write a script to modify the entries? Export data and edit it locally?

Any suggestions would be helpful.

share|improve this question

Presumably you can find all the dn's for entries where these attributes replace with something like ldapsearch '(attribute=value)' |grep ^dn and then for each entry make a ldapmodify script, so, using a bit of Python:

from subprocess import Popen, PIPE

for line in input:
    dn = line.rstrip().split()[1]
    modify_str = line
    modify_str += 'changetype: modify\nreplace: attribute\nattribute: newvalue'
    lm = Popen('ldapmodify <various args>', shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    (out, err) = lm.communicate(modify_str)
    if lm.wait() != 0:
        sys.stderr.write('ldapmodify of {0} failed:\n{1}'.format(dn, err))

I.e. for each entry you need to modify, generate a clause that states:

dn: MyEntryCN
changetype: modify
replace: attribute
attribute: newvalue

and feed that to ldapmodify (with the relevant authentication, etc command line arguments).

share|improve this answer
In fact, there exists a standard format (LDIF) for making bulk changes to an LDAP server in this way. – Handyman5 Jul 10 '11 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.