LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2007, 03:01 PM   #1
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Rep: Reputation: 15
ldapsearch


Hi everyone - By any chance would anyone know if you can do ldapsearch to list of the uid's (about 1000 of them that are saved in a text file) at once and put the output in a file?

I am only able to get one user at a time ... pls help...

I used this to get one uid information...but need to find them all...thanks in advance..

ldapsearch -L -h localhost -p 1521 -D "uid=admin,ou=cadmin,o=xyz.com" -w c_passwd -b o=abcd.com -s sub uid=00110rr
 
Old 11-15-2007, 03:08 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Put the "ldapsearch" command in a loop.

Pseudocode, not tested:

Quote:
while read UID
do
ldapsearch uid=$UID (whatever the right syntax is for ldapsearch)
done <filename
This works if filename is simply a list of the desired entries. If not, then you have to do more processing to extract the desired fields. (Post some sample entries from your file)
 
Old 11-15-2007, 03:29 PM   #3
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
I got an error...can you please take a look at this? I appreciate...

while
read UID
do ldapsearch -L -h localhost -p 5221 -D "uid=some_admin,ou=someadmin,o=abc.com" -w some_passwd -b o=abc.com uid=$UID somequestion someuserstatus
done <t.txt


how could I output all information needed to a file?

currently I get this error in the server:

scope should be base, one, or sub
usage: ldapsearch [options] filter [attributes...]
where:
filter RFC-1558 compliant LDAP search filter
attributes whitespace-separated list of attributes to retrieve
(if no attribute list is given, all are retrieved)
options:
-n show what would be done but don't actually search
-v run in verbose mode (diagnostics to standard output)
-t write values to files in /tmp
-u include User Friendly entry names in the output
-A retrieve attribute names only (no values)
-B do not suppress printing of non-ASCII values
-L print entries in LDIF format (-B is implied)
-R do not automatically follow referrals
-d level set LDAP debugging level to `level'
-F sep print `sep' instead of `=' between attribute names and values
-f file perform sequence of searches listed in `file'
-b basedn base dn for search
-s scope one of base, one, or sub (search scope)
-a deref one of never, always, search, or find (alias dereferencing)
-l time lim time limit (in seconds) for search
-z size lim size limit (in entries) for search
-h host ldap server
-p port port on ldap server
-D binddn bind dn
-w passwd bind passwd (for authentication)
-j file read bind passwd from `file'
-M authentication-mechanism CRAM-MD5
scope should be base, one, or sub
 
Old 11-15-2007, 03:57 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
In your first example, "uid" only appears once. In the second example, it appears twice.

I don't know all the nuances of ldapsearch, but take this absurdly simple example:

to find someone with last name "smith", I can do this:

Quote:
ldapsearch -x sn=smith
assuming this works, I can then do:

Quote:
name="smith"
ldapsearch -x sn=$name (here the shell substitutes the value of name before ldapsearch executes)
There should be similar functionality with any field name used by ldap. First, test the commands manually---then put them into the script.


Also, post some samples from your file......
 
Old 11-15-2007, 04:19 PM   #5
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
I apprciate for the assistance...I got it working I think it was typo...but works ok now...Thanks much again :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ldapsearch | ldapmodify eantoranz Linux - Software 1 01-28-2013 09:33 PM
LDAP > ldapsearch doesn't print the entries when bound as normal user cbonar Linux - Server 2 09-22-2007 01:19 PM
strange ldapsearch error PhillipHuang Linux - General 0 09-19-2006 12:27 AM
ldapsearch with incomplete base returns no results superhausi Linux - Software 0 10-25-2005 03:23 AM
OpenLDAP, ldapsearch: how to list all attributes Hko Linux - Networking 0 08-15-2004 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration