#!/bin/ksh
##############################################################################
#
# This scripts starts the Universal Agent's UDB client program (only)
#
# Note: The db2udb program needs to run under DB2 Administrator account
#
# Note: the following environment variables only need to be set if running
#       on a multi-home system or if host name not defined within DNS...
#		KUM_DCH_HOSTNAME
#		KUMP_DCH_HOST
#		KUMP_API_DPAPI_HOST
#
##############################################################################
bindir=`pwd`/$(dirname $0)
[ "$(print $0 | grep '\./')" = "" ] && [ "$(print $0 | grep '^/.*')" = "" ] && [ `pwd` = '/' ] && bindir=`pwd`$(dirname $0)
[ "$(print $0 | grep '^/.*')" != "" ] && bindir=$(dirname $0)

export TEXTDOMAINDIR=$bindir/../config/nls/msg
export PATH=$bindir:$PATH

export PATH=/usr/bin:$PATH
#$NLS-E$ "Starting Omegamon Monitor Agent for Universal Database"
nls_replace 'KCI0670I'
Product=ud

if [ -z "$CANDLEHOME" ]
then
   #$NLS-E$ "CANDLEHOME environment variable is not set..."
   nls_replace 'KCI0671E' CANDLEHOME
   exit 0
fi

grep "^BINARCH" $CANDLEHOME/config/k${Product}env > env_$$$
IFS="'"
read key Arch blank < env_$$$
rm env_$$$

Host=`hostname`

Config_File=${CANDLEHOME}/config/${Product}.config

if [ -f $Config_File ]
then
   . $Config_File
else
   #$NLS-E$ "Product is not configured..."
   nls_replace 'KCI0672I'
fi

$CANDLEHOME/${Arch}/${Product}/bin/kudagent > $CANDLEHOME/logs/${Product}.log 2>&1 &
pid=$!

mv $CANDLEHOME/logs/${Product}.log $CANDLEHOME/logs/${Host}_${Product}_${pid}.log

print "ud=$pid" >> $CANDLEHOME/config/${Host}_agents.run
