Hi Team
In the below code, irrespective of the if statement that gets executed, retcd is being assigned a standard value(1) instead of changing as per code. Could you please help to see where is it going wrong.
rval=0
CONF_FILE=/apps/wmroot/scripts/props/UMPath.properties
NOHUP="nohup"
getProperty()
{
prop_key=$1
prop_file=$2
prop_value=`cat ${prop_file} | grep ${prop_key} | cut -d'=' -f2`
}
#get properties
getProperty "value.UMPath" ${CONF_FILE}
UMPath=${prop_value}
echo "$UMPath"
# Clear any currently running tail commands which will cause the loop below to fail
ps -ef|grep -v grep|grep tail|grep $UMPath|grep nirvana.log > /dev/null
if (( $? == 0 )); then
echo -e "\nClearing the following tail commands:"
ps -ef|grep -v grep|grep tail|grep $UMPath|grep nirvana.log
ps -ef|grep -v grep|grep tail|grep $UMPath|grep nirvana.log|awk '{print $2}' | xargs kill -9
fi
#Finding the nserver.pid to see if UM is up
SERVER_PID=$UMPath/bin/nserver.pid
echo "Check if UM Server is running or not"
if [ -f $SERVER_PID ] ; then
echo "UM Server is running.."
exit $rval
else
echo "UM Server is down, starting it up"
su - wmroot -c "${NOHUP} "$UMPath/bin/nserver" &"
fi
# Watch the log file for the initialization string
getline()
{
echo -e "\nNow watching nirvana log for the Started Nirvana Realm string\c"
tail -f $UMPath/data/nirvana.log | while read line
do
echo ${line} | egrep "Realm Server Startup sequence completed" > /dev/null 2>&1
if (( $? == 0 )); then
echo -e "\nFound: ${line}\n"
echo "UM is now up and running"
retcd=0
return $retcd;
exit $retcd
fi
echo ${line} | egrep "Server shutdown" > /dev/null 2>&1
if (( $? == 0 )); then
echo -e "\nFound: ${line}\n"
echo "UM failed to start. Please check"
retcd=1
return $retcd;
exit $retcd
fi
done
}
getline
if [ "$retcd" = 0 ]
then
echo "server is now up"
else
echo "Server has been shutdown due to an error, please check"
fi
exit $rval