Changes

Jump to: navigation, search

stoney core: OpenLDAP ldapseach and replace

297 bytes added, 14:14, 14 December 2020
/* Search an replace - Replace a section (part) of an attribute */
Finally, we need to loop over all the lines of the result and replace a section (part) of the original (old) content to the attribute with a new section (part):
<source lang='bash'>
dn="" # Reset the dn to an empty stringcontent="" # Reset the content to an empty string
while 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
linecontent=${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 [ ${#dn} -ne 0 ]; then echo "# Afterdn: $line{dn}" fi
fi
done <<< "$result"
echo "Length: ${#line}"
echo "DN: $dn"
echo "Content: $content"
</source>
3,368
edits