You're viewing a comment by Catia Lavalle and its responses.

Catia Lavalle Permalink
February 18, 2009, 10:38

You did really a great job! But I still have 2 open questions. I explain with a practical example although there are many other situations where the same questions arise.

Say you have an LDAP directory and you want to add an attribute to all the entry of the directory which do not jet have it set.
First you do an LDIF export of your directory ending up with blocks of the kind:

dn: cn=Robert Smith,dc=bechtle,dc=de
objectClass: inetOrgPerson
cn: Robert Smith
cn: bob  smith
sn: smith
uid: rjsmith
carLicense: HISCAR 123
homePhone: 555-111-2222

dn: cn=Brad Marshall,dc=bechtle,dc=de
objectClass: inetOrgPerson
cn: brad marshall
sn: marshall
uid: bmarshall
carLicense: HISCAR 123
homePhone: 555-111-2222

then your problem is split in 3
1) Find which entry (1 dn: line = 1 entry identifier) already have the attribute already set
2) extract a list of all entries in the LDIF export except the ones in step (1) (which already have the attribute set)
3) write a script which use this entry list to add the missing attribute.

I know how to do the part (3). The problems are part (1) and (2) i.e. how to generate the list of entries to be modified. I have a solution but is not really elegant:

grep -n dn "export-secure.ldif" > ./tmp0.dat
grep -n vkek "export-secure.ldif" >> ./tmp0.dat
sort -n ./tmp0.dat | cut -d":" -f 2- | grep -B1 vkek | grep dn > ./list-vkek.dat

grep dn "export-secure.ldif" > ./tmp.dat
cp tmp.dat save.dat

for NAME in $(awk '{print $2}'  ./tmp1.dat
mv ./tmp1.dat ./tmp.dat


I am sure there are better ways.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "disk_128": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.