June 28, 2017

Why is Korn shell script not found from within another Korn shell script

We just installed our application, which contains numerous shell scripts, on Redhat 7 enterprise server., 64-bit, vmware machine. Our app also runs on a vmware machine that runs fine with Redhat 5 enterprise. A startup script also runs ok on the rhel 7 server, but when you're in a directory other than the base directory where the script is located, it behaves differently than the Redhat 5 server. The start script calls another shell script at different lines, and works fine when we're in the script's home directory. But when we run the start script from another directory, there are a couple of lines where the called script is not found. We don't get this behavior on Redhat 5. On Redhat 5 we can run the start script from any directory. Script name is do_start, and the script it's calling is is_running. Below is the do_start script. When running the do_start script from another directory, the script runs fine, and the initial calls to is_running work. However, it then fails on line 141 (is_running: not found [No such file or directory]). When we run the do_start again with the app running, it then fails on the other line, line 104. Have not been able to find any help on Google or access.redhat.com

#!/usr/bin/ksh

# Used to start <IM>,<LT> or <ID>'s using the ./etc/CONFIG.is_running file

test ! -r ~icadmin/sweet/setenv && echo "~icadmin/sweet/setenv not found. Good-bye." && exit 1
#test -z "$SET_ENV_READ" && . ~icadmin/sweet/setenv
. ~icadmin/sweet/setenv

env > /home/icadmin/env_notworking_dostart.out

test ! -r $SWEET_HOME/etc/im/SWEET_env && echo "$SWEET_HOME/etc/im/SWEET_env not found. Good-bye." && exit 1
. $SWEET_HOME/etc/im/SWEET_env

# Determine server Type - Primary or Secondary.
Rtn=`$SWEET_HOME/bin/serverType v`
ST=`echo $Rtn | cut -d":" -f1`
MSG=`echo $Rtn | cut -d":" -f2-9`
test "$ST" = "I" && echo "$SWEET_HOME/bin/serverType Error: $MSG" && exit 1

# get a list of IM's that can run on this server type
IMs=`egrep -v '^#' $SWEET_HOME/etc/CONFIG.is_running \
| egrep -e "<$ST>|<B>" | egrep -e "<IM>|<ID>|<LT>" | sort -n | nawk '{ print $4 }'`

NUM_IMS=1
verbose=

Usage()
{
cat << EOF
ERROR: ${@}
Usage: ${0} EngineName
-z Zero log file
-q quite
-l Display all Objects allowed to run on this server: listCONFIG.is_running -a
-h This message
-J Specify more arguments for the JAVA runtime engine
EOF

}

ZeroLog=0

while getopts zvqhlj:J: name ; do
case ${name} in
q )
verbose='-q'
;;
z )
ZeroLog=1
;;
l )
$SWEET_HOME/bin/listCONFIG.is_running -va
exit 0
;;
j | J )
Jopts=${OPTARG}
;;
h | ? )
Usage ${@}
exit 0
;;
esac
done
shift $((OPTIND -1))
test -z "$1" && Usage ${@} && exit 1

if fgrep -s ${SWEET_IM_PREFIX}$1 $SWEET_HOME/etc/CONFIG.is_running ; then
APP=${SWEET_IM_PREFIX}$1 ;
else
APP=$1 ;
fi

# Is the IM starting in the IMs list
for im in $IMs
do
test "$im" = $APP && GoodIM=yes && break
done

test -z "$GoodIM" \
&& echo "$APP is not allowed to run on this server: $MSG. See ../etc/CONFIG.is_running - <$ST> <IM>"\
&& exit 1

#optional _env files no error or warning message

if [ -r $SWEET_HOME/etc/im/${APP}_env ] ; then
#test -z "$verbose" && /usr/ucb/echo "Reading extra configuration file $SWEET_HOME/etc/im/${APP}_env";
test -z "$verbose" && echo "Reading extra configuration file $SWEET_HOME/etc/im/${APP}_env";
. $SWEET_HOME/etc/im/${APP}_env
fi

echo "first check of is_running"
which is_running
#START IMSE PROCESS
echo " $SWEET_HOME/bin: " $SWEET_HOME/bin
echo " APP: " ${APP}
PIDS=`cd $SWEET_HOME/bin; is_running -p ${APP}`
echo "PIDS: " $PIDS
NUM_RUNNING=`echo ${PIDS} | wc | nawk '{ print $2 }'`
echo "NUM_RUNNING: " $NUM_RUNNING
if [ ${NUM_RUNNING} -ge ${NUM_IMS} ]; then
#test -z "$verbose" && /usr/ucb/echo "${APP} is running ("`is_running -q -p ${APP}`")"
test -z "$verbose" && echo "${APP} is running ("`is_running -q -p ${APP}`")"
else
if [ "$ZeroLog" -eq "1" ] ; then
cat /dev/null > $LOG_DIR/${APP}.log ;
#test -z "$verbose" && /usr/ucb/echo -n "Cleared log..."
test -z "$verbose" && echo "Cleared log...\c"
fi

# use the following for running a repo from a Repository Server
#REPO="tibcr://${APP}:service=${IB_SERVICE}:network=${IB_NETWORK}:daemon=${IB_DAEMON}"
# use the following for running a repo from a file
REPO=${SWEET_HOME}/REPOS_DB/${APP}.dat
LogPostfix="";
while [ ${NUM_RUNNING} -lt ${NUM_IMS} ]; do
if [ ${NUM_RUNNING} -gt 0 ];then
LogPostfix=${NUM_RUNNING};
fi
#test -z "$verbose" && /usr/ucb/echo -n "starting ${APP} [${NUM_RUNNING}] .."
test -z "$verbose" && echo "starting ${APP} [${NUM_RUNNING}] ..\c"
nohup $ENG_JDK/bin/java $ENG_FLAGS \
${Jopts} \
-classpath "$IM_ENG_CLASSPATH:$SWEET_CLASSPATH" \
com.tibco.im.IMSe \
-name ${APP}${LogPostfix}.`hostname` \
-p $SWEET_HOME/etc/im/SWEET_Properties.cfg \
-p $SWEET_HOME/etc/im/QNET.cfg \
-p $SWEET_HOME/etc/im/${APP}.cfg \
-s ${IM_SUBJ_PREFIX}.${APP} \
${REPO} >> $LOG_DIR/${APP}${LogPostfix}.log 2>&1 &

#/usr/ucb/echo $! >> $SWEET_HOME/pid/${APP}.pid
echo $! >> $SWEET_HOME/pid/${APP}.pid

sleep 40
echo "second check of is_running"
which is_running
if (is_running -q ${APP}) ; then
#test -z "$verbose" && /usr/ucb/echo "done"
test -z "$verbose" && echo "done"
else
#test -z "$verbose" && /usr/ucb/echo "failed"
test -z "$verbose" && echo "failed"

# Call your notification script here....
# if [ -x ${SLAYER_HOME}/bin/sl_alarm ] ; then
# ${SLAYER_HOME}/bin/sl_alarm \
# -messageIdPrefix CRM \
# -messageIdNo ${msgId} \
# -messageGroup CRM \
# -application CRM \
# -applVersion ${ENV}${buildId} \
# -processName ${processNm} \
# -severity critical \
# -message "Failed to start ${APP}."
# fi

exit 1
fi
let NUM_RUNNING=${NUM_RUNNING}+1;
done
fi

Click Here!