I am writing a python command line script that takes a .ldif and two strings. The strings correspond to a key and a value that I need to insert at the end of each record in the .ldif file. However, I’m having an issue figuring out how to parse the .ldif file so that I know I’m at the end of a record. When I reach the end of a record I need to write to the file the two strings (Key: Value) with a colon in between them.
So basically I need to:
- Parse arguments from the command line (.ldif, string1, string2)
- Create the string I am going to append to the .ldif
- Open the .ldif and seek to the end of each record. Upon reaching the end of a record I need to write the string I created from string1 and string2.
- When I see the EOF of the .ldif I need to return the .ldif file with the updated records.
Before:
# example.ldif
dn: Aamir_005_000
cn: Aamir_25
givenname: Aamir
dn: Saul_024
cn: Saululite
givenname: Saul
After: python myscript.py ./example.ldif sillyname syllabear
# example.ldif
dn: Aamir_005_000
cn: Aamir_25
givenname: Aamir
sillyname: syllabear
dn: Saul_024
cn: Saululite
givenname: Saul
sillyname: syllabear
1 Answer