Last active
May 15, 2023 20:42
-
-
Save simonLeary42/dc7226a1ad41d200444ba00e9d23430f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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