Overview#

So, you got all these servers and all these indexes, how do you manage them?

We wrote a script to do just that.

The idea is that you could supply a txt file with all your indexes and use ndsindex to add|delete|suspend|resume|list them.

Here is the script.

NOTE:Use at your own risk and you will need to modify for your environment.

#!/bin/bash
#
# Reads from $2 to manage indexes
# $1 = Index Operation to perform add|delete|suspend|resume|list
#
# $2 = list of indexes or a full path to file containing indexes
#
# 8/11/2005 --Fixed problem with NDS attribute names that contain a space
#             Changed loop to run ndsindex for each index (this is so that
#              a single error will not cause all changes to fail)
#             Added a search for a .der matching the name of the tree
#             Changed how server DN is read
# 8/18/2005 --Fixed problem seen when multiple matching .der files found
#
# 7/15/2007 2:41:58 PM - Minor syntax changes and added documentation
#
# Assumes there is a ndsuser on this local host and that certificates for each tree are present in the
#  home directory for the ndsuser.
#
# infile File format follows:
#  indexDefinition  each index defintion should look like
#                  "<indexName>;<attributeName>;<indextype>" 
#                  where:
#                  indexName      Name you choose to name your index
#                  attributeName  Name of attribute to be indexed 
#                  indextype   Can be one of VALUE, SUBSTRING or PRESENCE 
#
# w1costCenter;costCenter;value
# w1FullName;fullName;value
# w1InternetEMailAddress;mail;value
# w1L;l;value
# w1Lob;b1Lob;value
# w1ObjectClass;objectClass;value
# NOTE: Please no spaces in Index Names We think this is fixed, but why use spaces ?
##########################################################################
indexOP=$1
infile=$2

# Validate parameters
case $indexOP in
add|delete|suspend|resume|list)
	printf "\nYou have specified index operation: $indexOP.\n\n"
 	;;
*)
	printf "\nUnrecognized index operation: $indexOP.\n"
	printf "Valid paramters are:  add|delete|suspend|resume|list\n"
	exit 1
;;esac
if [ "$indexOP" != "list" -a ! -f "$infile" ]
then
	printf "\nIndex definition file not found: $infile.\n"
	printf "Usage:  ./indexMan.sh [add|delete|suspend|resume] [index definition input file]\n"
	exit 1
fi

# Initialize variables
#unset indexdefs
ndsUserHome=`cat /etc/passwd | grep ndsuser | cut -d: -f6`
treename=`ndsconfig get n4u.base.tree-name | cut -d= -f2`
LDAP1=localhost
CERT1=`find $ndsUserHome -name $treename.der | tail -1`
BaseDN1=dc=willeke,dc=com
ADMIN1=cn=admin,ou=Administration,$BaseDN1
SVR1="cn=`ndsconfig get n4u.nds.server-name | cut -d= -f2`,`ndsconfig get n4u.nds.server-context | cut -d= -f2- | tr . ,`"
NDSINDEX=/usr/ldaptools/bin/ndsindex
printf "\nLDAP1 = IP or DNS server of LDAP to write changes to.\n"
printf "CERT1 = Path to SSL certificate file (der format).\n"
printf "ADMIN1 = LDAP FQDN format of ID with rights to make changes (e.g. cn=admin,o=novell).\n"
printf "SVR1 = LDAP FQDN format of server indexes to change (e.g. cn=SERVER,ou=SVR,O=novell).\n\n"
for var in LDAP1 CERT1 ADMIN1 SVR1
do
	printf "$var [${!var}]: "
	read input
	if [ -n "$input" ]
	then
		eval $var=\"$input\"
	fi
done

printf "\nThese parameters will be used:\n"
for var in LDAP1 CERT1 ADMIN1 SVR1
do
	printf "$var = ${!var}\n"
done

if [ -z "$password" ]
then
	# Get the admin password
	printf "\nEnter the password for $ADMIN1: "
	stty -echo
	read password
	stty echo
	printf "\n\n"
fi

if [ "$indexOP" != "list" ]
then
	# Read index names/definitions into a variable
	while read line
	do
		if [ "$indexOP" != "add" ]
		then
			# Get only the index name
			line=`echo $line | cut -d";" -f1`
		fi
		if [ -z "$CERT1" ]
		then
			$NDSINDEX $indexOP -h $LDAP1 -Z -D"$ADMIN1" -w$password -s"$SVR1" "$line"
			echo "^--- -$indexOP- $line."
		else [ -n "$CERT1" ]
			$NDSINDEX $indexOP -h $LDAP1 -e"$CERT1" -D"$ADMIN1" -w$password -s"$SVR1" "$line"
			echo "^--- -$indexOP- $line."
		fi
	done < <(grep -v "^#" $infile)
else
	if [ -z "$CERT1" ]
	then
		$NDSINDEX $indexOP -h $LDAP1 -Z -D"$ADMIN1" -w$password -s"$SVR1"
	else [ -n "$CERT1" ]
		$NDSINDEX $indexOP -h $LDAP1 -e"$CERT1" -D"$ADMIN1" -w$password -s"$SVR1"
	fi
fi
#### END OF SCRIPT #############

More Information#

There might be more information for this subject on one of the following:

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-3) was last changed on 26-Dec-2013 13:43 by jim