From: Ian Macdonald Date: 2003-07-16T18:01:18+09:00 Subject: Re: ldap with ruby confusion On Wed 16 Jul 2003 at 14:25:30 +0900, Cere Davis wrote: > I have this piece of code that I modified based on search.rb in the ldap > package for Ruby. > > Something isn't working correctly with this code but I cannot find a way > to get the code to jsut printt regular ldap output instead of only > printing hashes or error messages when an exception is caught. Does > anyone know of a way that I can get just regular output that is similair > to just using the ldapsearch utility? > > require 'ldap' > > HOST="directory.washington.edu" > BASE="ou=People, o=University, c=US" > > LDAP::Conn.new(HOST, LDAP::LDAP_PORT).bind{|conn| > conn.perror("bind") > begin > conn.search(BASE, > LDAP::LDAP_SCOPE_SUBTREE, > "(objectclass=*)" > ){|e| > p e.keys > } > rescue LDAP::ResultError => msg > $stderr.print(msg) > end > } Try something like this: #!/usr/bin/ruby -w require 'ldap' HOST = 'ldap.corp.foo.com' BASE = 'ou=People,dc=foo,dc=com' LDAP::Conn.new(HOST, LDAP::LDAP_PORT).bind do |conn| begin conn.search(BASE, LDAP::LDAP_SCOPE_SUBTREE, '(objectclass=*)') do |entry| entry.to_hash.each do |key, values| values.each do |value| printf('%s: %s\n', key, value) end end puts end end end That'll do what you're looking for, I think. Ian -- Ian Macdonald | A committee is a life form with six or more System Administrator | legs and no brain. -- Lazarus Long, "Time ian@caliban.org | Enough For Love" http://www.caliban.org | |