Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have around 10 users who have been given access to one specific application which uses AD authentication.

ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=xyz | grep displayName

Can sAMAccountName be made to refer to my entire list of users (which is a seperate text file) at once? If not, Can we just put this command into a script and let the user enter their sAMAccountName and check if they exist in AD?

Any thoughts on this...

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

I might not understand this clearly but if you wanted to put it in a script you could write a bash script like below to prompt for an account name.

#!/bin/bash
echo -n "Please enter username to lookup: "
read USERNAME
DISPLAYNAME=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$USERNAME | grep displayName`

if [ -z "$DISPLAYNAME" ]; then
  echo "No entry found for $USERNAME"
else 
  echo "Entry found for $USERNAME"
fi
share|improve this answer
add comment

Your script will have to create a proper LDAP filter with all the usernames:

(|(sAMAccountName=foo)(sAMAccountName=bar)(sAMAccountName=baz))

For example:

filter="(|"
while read -r name; do
    filter+="(sAMAccountName=${name})"
done
filter+=")"

(| ... ) is OR in LDAP. The AND operator is (& ... ).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.