20110729 listindexespl for dsee7 - plembo/onemoretech GitHub Wiki

title: listindexes.pl for dsee7 link: https://onemoretech.wordpress.com/2011/07/29/listindexespl-for-dsee7/ author: lembobro description: post_id: 14 created: 2011/07/29 14:37:24 created_gmt: 2011/07/29 14:37:24 comment_status: open post_name: listindexespl-for-dsee7 status: publish post_type: post

listindexes.pl for dsee7

This is a script to take the output of Directory Server Enterprise Edition’s dsconf list-indexes -v and turns it into a csv. Besides making a nice report, the output can also be used for comparing indexes on different DSEE directories and as input to a script that formats index creation and modification commands. In other words, endless fun. Here is the script, be mindful that like everything else on this site I only care if it works for me. It does. Create input by running:

dsconf list-indexes -h localhost -p 389 -v dc=example,dc=com

Then modify the script for items like file paths, etc.

#!/usr/bin/perl
# listindexes2csv.pl
# Parses long form index list created with dsconf list-indexes -v and makes csv
# suitable for running through setindexes.pl script.
# Data: ATTR_NAME eq-enabled  pres-enabled  sub-enabled  approx-enabled  system
# Trim header and any indexes you don't want before parsing.
# Created 7/29/2010 by P Lembo

use strict;
use Custom::Text::ParseWords;

my $HOME = $ENV{'HOME'};
my $infile = "$HOME/data/admin/testserver-indexes.txt";
my $outfile = "$HOME/data/admin/testserver-indexes.csv";

open FH, ">$infile" or die $!;

open FH1, ">$outfile" or die $!;

while() {
  chomp;

  my ($ATTR,
      $eq,
      $pres,
      $sub,
      $approx,
      $system

  ) = ( &parse_line('s+',0,$_));

  my @props;

  print FH1 "$ATTR";
  print FH1 ",";
  if($eq eq 'on') {
      push @props, "eq";
  }
  if($pres eq 'on') {
      push @props, "pres";
  }
  if($sub eq 'on') {
      push @props, "sub";
  }
  if($approx eq 'on') {
      push @props, "approx";
  }
  if($system eq 'yes') {
      push @props, "system";
  }

  my $propstr;
  foreach my $prop(@props) {
      $propstr = $propstr . " ". $prop;
  }
  for ($propstr) {
      s/^s+//;
      s/s+$//;
  }
  print FH1 $propstr;

  print FH1 "n";
}

close FH1;
close FH;

__END__;

What you’ll wind up with is a file whose data looks something like this:

cn,pres eq sub
entrydn,eq
givenName,pres eq sub
mail,pres eq sub

and so on. And yes, I know, I could use a refresher in how to handle perl arrays.

Copyright 2004-2019 Phil Lembo