search并replaceldap属性

我在LDAP服务器中有相当大的一组数据。 有些属性出现在很多地方,我想replace它们。

数据不是很大,但只要手动排除编辑和导出就足够了。

最好的办法是什么? 使用LDAP工具来查找并replace它们? 写一个脚本来修改条目? 导出数据并在本地进行编辑?

任何的意见都将会有帮助。

大概你可以find所有的dn的条目,这些属性取代了像ldapsearch '(attribute=value)' |grep ^dn ,然后为每个条目做一个ldapmodify脚本,所以,使用一点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)) 

也就是说,您需要修改每个条目,生成一个条款,指出:

 dn: MyEntryCN changetype: modify replace: attribute attribute: newvalue 

并将其提供给ldapmodify (使用相关的authentication等命令行参数)。