Changes

Jump to: navigation, search

stoney core: OpenLDAP ldapseach and replace

279 bytes removed, 12:34, 14 December 2020
/* Search an replace - Replace a section (part) of an attribute - Step by step */
We need to create an array of the the complete result:
<source lang='bash'>
redultresult=$(ldapsearch -LLL -x -s children \
-H "$ldap_server" \
-b "$ldap_base" \
-D "$ldap_bind_account" \
-w "$ldap_bind_password" \
"(${ldap_attribute}=*${ldap_attribute_old}*)" \ | awk '{ if (/^ /) { sub(/^ /, ""); } else printf "\n"; printf "%s", $0 }' \ | awk '/^dn: / { print $2 }'
)
</source>
Finally, we need to loop over all the distinguished names and replace the original (old) content to the attribute with the new content:
<source lang='bash'>
for dn line in $childrenresult
do
cat <<EOF | sed 's/^ \{4\}//' | ldapmodify -x \ -H echo "# $ldap_serverline" \ -D "$ldap_bind_account" \ -w "$ldap_bind_password" dn: ${dn} changetype: modify replace: ${ldap_attribute} ${ldap_attribute}: ${ldap_attribute_new}EOF
done
</source>
3,368
edits