Re: Handling output from ldapsearch
- From: schlenk <schlenk@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jun 2008 07:01:57 -0700 (PDT)
utbl...@xxxxxxxxx wrote:
In the following example output (from an exec call to ldapsearch) am
trying to figure out how to just derive a list of the sAMAccountName
values:
"dn: CN=user01,CN=Users,DC=mynet,DC=local
sAMAccountName: user01
dn: CN=user02,CN=Users,DC=mynet,DC=local
sAMAccountName: user02
dn: CN=user03,CN=Users,DC=mynet,DC=local
sAMAccountName: user03"
...ideally, resulting in a list like this (based on above):
"user01 user02 user03"
Have tinkered with regexp/lsearch et al (for many hours now), searched
various wiki's, google and also scanned Mr Welch's good book for clues
but still no luck ...apart from realising my skills are very much at
beginner level. What's the best way to approach this?
BTW ...would prefer *not* to write ldapsearch output to a file and
then read in the file if possible.
I'm biased, because i maintain the ldap module, if you can use the
tcllib ldap module
(it does not support all auth methods yet and not all features like
following referrals correctly)
package require ldap
set conn [ldap::connect ldap.yourdomain.com]
ldap::bind $conn user {password}
set res [ldap::search $conn {baseDN} {(objectClass=person)}
sAMAccountName]
set accountlist [lsearch -index {1 1} -all -inline -subindices $res]
ldap::disconnect $conn
http://tcllib.sf.net/doc/ldap.html
Otherwise if you need to use ldapsearch it should work with some
regexping...
Michael
.
- References:
- Handling output from ldapsearch
- From: utbloke
- Handling output from ldapsearch
- Prev by Date: Handling output from ldapsearch
- Next by Date: Re: Handling output from ldapsearch
- Previous by thread: Handling output from ldapsearch
- Next by thread: Re: Handling output from ldapsearch
- Index(es):