20120301 netscape family directory index lists using ldapsearch perl - plembo/onemoretech GitHub Wiki
title: Netscape family directory index lists using ldapsearch & perl link: https://onemoretech.wordpress.com/2012/03/01/netscape-family-directory-index-lists-using-ldapsearch-perl/ author: lembobro description: post_id: 2285 created: 2012/03/01 15:20:32 created_gmt: 2012/03/01 19:20:32 comment_status: closed post_name: netscape-family-directory-index-lists-using-ldapsearch-perl status: publish post_type: post
Netscape family directory index lists using ldapsearch & perl
Just a simple tutorial on how to get a list of indexes from a Netscape family directory server using ldapsearch.
ldapsearch -x -LLL -h ldap1 -D "cn=directory manager" -W
-b "cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"
-s one "objectclass=nsindex"
This will just list all the indexes for the "userRoot" database. You can pipe it to a file (e.g. ">indexes.ldif") or use the following code to create a csv formatted list (index types found in the second field are a pipe-delimited list):
#!/usr/bin/perl
use strict;
use Net::LDAP;
use Net::LDAP::Entry;
my $HOME = $ENV{'HOME'};
our($dirHost, $dirUsr, $dirPass);
require "$HOME/conf/scripts.conf";
my $outfile = "$HOME/data/userrootidx.csv";
my $basedn = "cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config";
my $query = "(objectclass=nsindex)";
my $ldap = Net::LDAP->new($dirHost);
my $mesg = $ldap->bind($dirUsr, password =>$dirPass) or die $!;
open FH, ">$outfile" or die $!;
print FH "Index Name,IndexTypes,SysIdxn";
$mesg = $ldap->search (
base =>$basedn,
scope => 'one',
filter => $query
);
while (my $entry = $mesg->shift_entry()) {
my $dn = $entry->dn;
my $cn = $entry->get_value('cn');
my @nsindextype = $entry->get_value('nsindextype');
my $nssystemindex = $entry->get_value('nssystemindex');
my $indextypestr;
foreach my $indextype(@nsindextype) {
$indextypestr = $indextype . "|" . $indextypestr;
}
for ($indextypestr) {
s/^|//;
s/|$//;
}
print FH "$cn,$indextypestr,$nssystemindexn";
}
$ldap->unbind;
close FH;
__END__;
Copyright 2004-2019 Phil Lembo