Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

input=('searchoutput.txt')
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

 
discard

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.