Created
April 19, 2017 09:30
-
-
Save yumminhuang/fabbaa65cc08bf21a6c11b3ddde840d0 to your computer and use it in GitHub Desktop.
Check whether the given user is active in LDAP
This file contains 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 | |
LDAP_URI="ldap://ldap.company.cn:3268" | |
BIND="cn=infosys,ou=Group,dc=company,dc=local" | |
BASE="dc=company,dc=local" | |
PASSWORD="password" | |
userid=$1 | |
res=`ldapsearch -x -H $LDAP_URI -b $BASE -D $BIND -w $PASSWORD "(sAMAccountName=${userid})" -LLL msExchUserAccountControl | grep msExchUserAccountControl | awk -F' ' '{print $2}'` | |
if [ "$res" -eq "2" ]; then | |
echo 'Disabled' | |
fi | |
if [ "$res" -eq "0" ]; then | |
echo 'Active' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required to install ldapsearch first.
Usage: