Skip to content

Instantly share code, notes, and snippets.

@yumminhuang
Created April 19, 2017 09:30
Show Gist options
  • Save yumminhuang/fabbaa65cc08bf21a6c11b3ddde840d0 to your computer and use it in GitHub Desktop.
Save yumminhuang/fabbaa65cc08bf21a6c11b3ddde840d0 to your computer and use it in GitHub Desktop.
Check whether the given user is active in LDAP
#!/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
@yumminhuang
Copy link
Author

Required to install ldapsearch first.

Usage:

./ldap_user_active.sh username

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment