Skip to content

Instantly share code, notes, and snippets.

@volure
Created August 22, 2016 21:41
Show Gist options
  • Save volure/7e773792b997561340cd82e35633a205 to your computer and use it in GitHub Desktop.
Save volure/7e773792b997561340cd82e35633a205 to your computer and use it in GitHub Desktop.
#!/bin/bash
#usage
# ./search.sh "(uid=person)" mail
# returns the "mail" value from uid person
ldaphost=ldap://server:389
ldapuser=cn=config
ldappass=password_hele
if [[ -z "$2" ]]
then
ldapsearch -H $ldaphost -D "$ldapuser" -w "$ldappass" -ZZ "$1"
else
ldapsearch -H $ldaphost -D "$ldapuser" -w "$ldappass" -ZZ "$1" "$2" | sed -n "/^ /{H;d};/$2:/x;\$g;s/\n *//g;s/$2: //gp"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment