LDIF: Modify attr if exists; Add if not exists
The right way to do this is simply using the replace action
dn: ...
changetype: modify
replace: attributeName
attributeName: xxx
ldapmodify
has a -c
flag:
-c continuous operation mode (do not stop on errors)
... which I guess should take care of your first point.
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.