ANY=NO
TMPDIR=$ORACLE_HOME/ldap/load


if [ -z "$1" ] ;then
TERMINATE="NO"
fi
case $1 in

	-k) TERMINATE="YES";;

	?| -h) clear
	       echo <<USAGE_LDAPCHECK
Syntax: ldapcheck 

ldapcheck   Checks all OIDLDAPD Processes
ldapcheck -k	Kill all OIDLDAPD Processes
ldapcheck program		Checks the Single Program for 
[?|-h Help | Program (to check) | -k (kill processes)] [Program (to kill)]

Program		Description
---------	---------------------------------------
oidmon  	Oracle Internet Directory Server Guard Program
oidldapd 	Oracle Internet Directory LDAP Server
oidrepld 	Oracle Internet Directory Replication Server
USAGE_LDAPCHECK
exit 0
			   ;;

	*) TERMINATE="NO"
	   SINGLE=$1       ;;
esac

if [ -z "$SINGLE" ] ; then
SINGLE="NO"
fi

if [ -z "$2" ] ; then
	PARAM="NO"
else
	SINGLE=$2
fi

TMP="${TMPDIR}/$$.web"


#clear
echo " "
echo "Checking Oracle Internet Directory Processes ..."
echo " "

TMP="${TMPDIR}/$$.web"
ps -elf > $TMP
#
#Processes to Look for
#
case $SINGLE in

	NO)
FILES="oidmon oidldapd oidrepld"
	;;

	*)
FILES="$SINGLE"
	;;
esac
for prog in `echo $FILES`
do

	IFS="
";export IFS
	if (grep ${prog} $TMP >${TMPDIR}/null 2>&1 )
	then
	for proc in `grep ${prog} $TMP| grep -v ldapcheck`
	do
	IFS=" ";export IFS
#	echo ${proc}
	set ${proc}
	shift
	PID=$3
	case $TERMINATE in
		YES) 	echo "Terminating ${prog} on process ${PID}"
			kill -9 ${PID}
			ANY=YES
			;;

		*) 	echo "Process ${prog} is Alive as PID ${PID} "
			ANY=YES
			;;
	esac
	done
	else
		echo "Not Running ---- Process ${prog}"
	fi
done
case $ANY in

	NO) echo "No LDAP Processes are Running" ;;

	*)						;;
esac

rm -f $TMP
exit 0
