ypcat has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
I am trying to get Net::LDAP to allow me to send many queries to an LDAP database and return each one of the queries attributes and values to STDOUT as it runs.
Here is what I have tried so far and although it seems to be running every search query, it only writes to the screen the last query results.
I am trying to get Net::LDAP to allow me to send many queries to an LDAP database and return each one of the queries attributes and values to STDOUT as it runs.
Here is what I have tried so far and although it seems to be running every search query, it only writes to the screen the last query results.
For example, my macs.txt contains 10 Mac addresses. When they are sent to LDAP 1 at a time as you will see in the code below only the 10th MAC addresses attributes and values will be returned. Again my goal is to return all attributes and values from every query(all 10 macs).
I appreciate everyone's help. Here is the code.
I appreciate everyone's help. Here is the code.
use Net::LDAP; my $server = "192.168.0.20"; my $port = "389"; my $connection = Net::LDAP->new($server, port => $port) or die "Unable + to connect to $server:", @$, "\n"; $connection->bind() or die "could not bind: $@\n"; print "\n\nConnected to LDAP\n\n"; my @attrs = ['username', 'plan', 'ipaddress']; open MACS, "macs.txt" or die "Couldn't open the file or die: $!\n"; @macs = <MACS>; close MACS; print "Opened the Macs file\n"; my $count=0; foreach my $mac (@macs) { $count++; print "Processing: $count\n"; ldapsearch($mac); } sub ldapsearch { my $mac = shift; print "$mac\n"; my $searchobj = $connection->search( base => 'o=ldap, filter => "cn=$mac", attrs => @attrs, callback => \&callback, ); $searchobj->code && die $searchobj->error; } sub callback { my ($searchobj, $entry) = shift @_; $entry = $searchobj->shift_entry; if ($entry) { print $entry->dn, "\n"; print $entry->get_value('plan'); print $entry->get_value('ipaddress'); print $entry->get_value('username'); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Net::LDAP doesn't return until end of loop
by lachoy (Parson) on Jun 28, 2003 at 16:14 UTC | |
by ypcat (Beadle) on Jun 30, 2003 at 22:01 UTC | |
by lachoy (Parson) on Jul 01, 2003 at 01:48 UTC | |
by ypcat (Beadle) on Jul 01, 2003 at 05:07 UTC | |
by lachoy (Parson) on Jul 01, 2003 at 12:21 UTC | |
by ypcat (Beadle) on Sep 17, 2003 at 06:26 UTC | |
Re: Net::LDAP doesn't return until end of loop
by archon (Monk) on Jun 28, 2003 at 03:35 UTC |
Back to
Seekers of Perl Wisdom