4

Is there a way to do one of the following in an LDIF file?

  • Ignore error (attr not found) when trying to delete an attribute

Or:

  • If attribute exists, modify it
  • If it doesn't exist, add it
5

The right way to do this is simply using the replace action

dn: ...
changetype: modify
replace: attributeName
attributeName: xxx
4

ldapmodify has a -c flag:

-c         continuous operation mode (do not stop on errors)

... which I guess should take care of your first point.

2
  • Oddly, using -c doesn't seem to do anything. According to the man page this is exactly what I want. Excellent answer... if it worked. I tested and confirmed ldapmodify works fine if I remove the delete: of the non-existent attribute and errors (16) with or without -c otherwise. – user1844882 Jan 21 '13 at 17:40
  • 1
    Solved: Problem was that it has to be done in completely separate entries in the LDIF -- one entry for the delete, then another separate entry for successive actions such as add. – user1844882 Jan 21 '13 at 21:34
1
dn: ...
changetype: modify
add: attributeName
attributeName: xxx
-
delete: attributeName 
attributeName: value
-
delete: attributeOther

May also work for you. This allows multiple operations while listing the DN once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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