Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
Last active May 15, 2023 20:42
Show Gist options
  • Select an option

  • Save simonLeary42/dc7226a1ad41d200444ba00e9d23430f to your computer and use it in GitHub Desktop.

Select an option

Save simonLeary42/dc7226a1ad41d200444ba00e9d23430f to your computer and use it in GitHub Desktop.
#!/bin/bash
# assuming that username is LDAP `cn` and email is LDAP `mail`
USERS="ou=users,dc=unity,dc=rc,dc=umass,dc=edu"
ldapsearch -LLL -x -o ldif-wrap=no -b $USERS mail cn |
grep -v dn: | # delete lines that have `dn:`
tr '\n' ',' | # replace newlines with command
sed -r 's/\,{2,}/\n/g' | # replace multiple commans with a newline
sed -r 's/mail: (.*),cn: (.*)/cn: \2,mail: \1/g' | # if string is `mail,cn` rearrange it to be `cn,mail`
sed 's/mail: //g' | # remove `mail: `
sed 's/cn: //g' # remove `cn: `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment