Changes

Jump to: navigation, search

stoney core: OpenLDAP ldapseach and replace

949 bytes added, 11:30, 14 December 2020
/* Search an replace - Replace the content of sstMailFrom attribute */
= Search an replace =
== Search an replace - Replace the content of sstMailFrom attribute ==
=== Search an replace - Replace the content of sstMailFrom attribute - Variable definitions ===
<source lang='bash'>
# Set the following bash variables
</source>
=== Search an replace - Replace the content of sstMailFrom attribute - Step by step ===
Execute the search to retrieve all occurrences of the given search filter (ldap attribute and attribute value):
<source lang='bash'>
Finally, we need ti loop over all the distinguished names and replace the original (old) content to the attribute with the new content:
<source lang='bash'>
for dn in $children
do
cat <<EOF | sed 's/^ \{4\}//' | ldapmodify -x \
-H "$ldap_server" \
-D "$ldap_bind_account" \
-w "$ldap_bind_password"
dn: ${dn}
changetype: modify
replace: ${ldap_attribute}
${ldap_attribute}: ${ldap_attribute_new}
EOF
done
</source>
 
=== Search an replace - Replace the content of sstMailFrom attribute - Putting it all together (copy and past version) ===
<source lang='bash'>
children=$(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 }'
)
for dn in $children
do
3,368
edits