Changes

stoney core: OpenLDAP ldapseach and replace

1,105 bytes added, 15:13, 14 December 2020
Michael moved page [[stoney core - OpenLDAP: ldapseach and replace]] to [[stoney core: OpenLDAP ldapseach and replace]]
# Check, if the line starts with the ldap attribute of which we want to replace a part of the content
if [[ "$line" =~ ^${ldap_attribute}.* ]]; then
contentnew_content=${line//${ldap_attribute_old}/${ldap_attribute_new}} # Replace all matches of ${ldap_attribute_old} with ${ldap_attribute_new}.
fi
if [ ${#line} -eq 0 ]; then
if [ $ cat <<EOF | sed 's/^ \{#dn4\} //' | ldapmodify -ne 0 ]; thenx \ echo -H "$ldap_server" \ -D "$ldap_bind_account" \ -w "$ldap_bind_password" ${dn} changetype: modify replace: ${dnldap_attribute}" fi ${new_content}EOF
fi
done <<< "$result"
echo "Length: if [ ${#linedn}-ne 0 ]; then cat <<EOF | sed 's/^ \{4\}//' | ldapmodify -x \ -H "$ldap_server" \ echo -D "DN: $dnldap_bind_account"\ echo -w "Content: $contentldap_bind_password" ${dn} changetype: modify replace: ${ldap_attribute} ${new_content}EOFfi
</source>
=== Search an replace - Replace a section (part) of an attribute - Putting it all together (copy and paste version) ===
<source lang='bash'>
childrenresult=$(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="" # Reset the dn to an empty stringcontent="" # Reset the content to an empty stringwhile IFS= read -r line; do if [[ "$line" =~ ^dn.* ]]; then dn=$line fi # Check, if the line starts with the ldap attribute of which we want to replace a part of the content if [[ "$line" =~ ^${ldap_attribute}.* ]]; then new_content=${line//${ldap_attribute_old}/${ldap_attribute_new}} # Replace all matches of ${ldap_attribute_old} with ${ldap_attribute_new}. fi if [ ${#line} -eq 0 ]; then cat <<EOF | sed 's/^ \{4\}//' | ldapmodify -x \ -H "$ldap_server" \ -D "$ldap_bind_account" \ -w "$ldap_bind_password" ${dn} changetype: modify replace: ${ldap_attribute} ${ldap_attribute}: ${new_content}EOF fidone <<< "$result"if [ ${#dn} -ne 0 ]; then
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_newnew_content}
EOF
donefi
</source>
[[Category: OpenLDAP directory]]
SLB, editor, reviewer
3,368
edits