You may wish to try the Net::LDAPapi module. It uses the OpenLDAP C api to do the processing, rather than perl, which can make it more efficient for some types of processing.

--Quanah

--On December 17, 2007 3:11:57 PM +0100 Didi <[EMAIL PROTECTED]> wrote:

Hi

I am trying to generate my /etc/passwd from my ldap as a backup
solution. For this I wrote a little script. Unfortunately with having
20530 users in my LDAP (expected to increase) the script takes
real    0m21.471s
to execute and uses up to 370 MB of Memory. (While using 100 % Percent
of one Core (AMD Athlon(tm) 64 X2 Dual Core Processor 4600+))

Has someone got an idea how I can make this a little more efficient. I
tried both
- foreach my $entry ($mesg->entries) {
- while (my $entry=$mesg->pop_entry ( )){

It seams like the search first fills it's buffer and then proceeds.

Thank you in advance.

Cheers for the great work

Didi


-------Code-----

# !/usr/bin/perl
# A little program that creates a /etc/passwd from ldap
use strict;
use Net::LDAP;

# Please modify appropriate
my $ldap = Net::LDAP->new("lxb5479.cern.ch") or die "Error in creating
new Connection: $@";;

$ldap->bind("cn=Manager,dc=example,dc=edu", password=>"no_you_dont");

my $mesg = $ldap->search(filter=>"(&(objectClass=posixAccount)(uid=*))",
base=>"ou=People,dc=example,dc=edu");

$mesg->code && die $mesg->error;

######### !!!DO NOT TOUCH!!!##########

# foreach my $entry ($mesg->entries) {

while (my $entry=$mesg->pop_entry ( )){

  # Get rid of {crypt}
  my $a = $entry->get_value("userPassword");
  $a =~ s/\{crypt\}//g;

  my $line = join (":", $entry->get_value("uid"),
                   $a ,
                   $entry->get_value("uidNumber")  ,
                   $entry->get_value("gidNumber")  ,
                   $entry->get_value("gecos")  ,
                   $entry->get_value("homeDirectory")  ,
                   $entry->get_value("loginShell") );
  print $line . "\n";
}

$ldap->unbind;

# end


----
www.ribalba.de
Email / Jabber: [EMAIL PROTECTED]
Phone (Work) : +41 22 7679376
Skype : ribalba



--

Quanah Gibson-Mount
Principal Software Engineer
Zimbra, Inc
--------------------
Zimbra ::  the leader in open source messaging and collaboration

Reply via email to