Re: Re: Total number of LDAP entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 10 March 2009 17:38:33 Branimir wrote:
> David Boreham wrote:
> > Branimir wrote:
> >> well, I know that I can perform search and count them. I hoped that
> >> there is some shell command implemented in FDS that could provide this
> >> number. I administer commercial LDAP solution that provides such
> >> command. In my case this commercial solution charges per directory
> >> entry so I always have to know entry count. I was hoping FDC has some
> >> kind of equivalent command.
> >
> > Pipe the search output through grep and wc to count the entries returned.
>
> Thanks David. I am familiar with UNIX basics :). As I said before, I was
> hoping there is some simple command for this, nothing more.
>
> Cheers,
>
> Branimir
>
Here's an easy perl script you can run,  it will do a sub search on a given suffex and output the total entries returned.

Ryan


#!/usr/bin/perl

use strict;
use Net::LDAP;

my $bind_dn = "cn=directory manager";
my $bind_pw = "password";
my @servers = qw(server1.com server2.com);
my $base_dn = "cn=config";

foreach my $server (@servers) {

	my $ldap = Net::LDAP->new($server, port => '389', timeout=>10);
	if ( ! $ldap )
	{
			
			# return 0 here for a failed attempt
			print "failed to connect to $server\n";
			return 0;
	}
	my $msg = $ldap->bind ( $bind_dn,password => $bind_pw ,version => 3 );

	if ($msg->code) {
		# print error message here because we have access to the $msg object
		print "\t$server\t\t\tFAILURE " . $msg->code . " error text is " . $msg->error_name . "\n";
		
		return 0;
	}
	
	$msg = $ldap->search(filter=>"objectClass=*",  base=>$base_dn,scope => 'sub' );
	
	print "Found " . $msg->entries . " total entries in $base_dn on $server\n";
}

--
Fedora-directory-users mailing list
Fedora-directory-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-directory-users

[Index of Archives]     [Fedora Directory Users]     [Fedora Directory Devel]     [Fedora Announce]     [Fedora Legacy Announce]     [Kernel]     [Fedora Legacy]     [Share Photos]     [Fedora Desktop]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Big List of Linux Books]     [Gimp]     [Yosemite News]

  Powered by Linux