V
V
vlarkanov2019-07-09 13:50:46
linux
vlarkanov, 2019-07-09 13:50:46

Ldapsearch: how to get a list of CNs of all users in an OU (and its "subOUs") that have a non-empty mail field?

Actually, subject. I wrote a script that receives an email, position, phone number, etc. via CN. - and using this data generates a corporate signature for Postfix. Now we need to get a list of users who have mail in order to create signature files for all of them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2019-07-09
@vlarkanov

Yes, it’s easier than a steamed turnip:

ldap_basedn="dc=mydomain,dc=loc"
[email protected]
ldap_common_filter="(&(sAMAccountName=*)(mail=*))"

# Do LDAP search and keep results
ldapsearch -D $ldap_binddn -w qwertyasdf -LLL -h 192.168.1.14 \
           -b $ldap_basedn -P 3 -a always $ldap_common_filter mail phone другие-атрибуты

To check that the field is simply filled, no matter what, it is enough to put field=*. In the example above, all records with sAMAccountName AND mail fields filled in will be selected. To limit the search to a specific OU, it is written in ldap_basedn.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question