Guru's,
I want to make a use of "exec" command in my script and want to check return code of executing script, but as you know exec command will terminate current processID and comeout and will trigger new one, i am unable to check return code of script and not able to run a scrpit after exec.
so can you please help me to fix or give alternative to trigger a script.
Basically i am trying to check add a check whether script A is running or not if NO then it will trigger another instance of same script.
Script :
#!/usr/bin/ksh
LOG_FILE=/GEM_PILOT/custom/script/cx_log
SERVER="${HOSTNAME}";
USER=`whoami`
CURRENT_PROCESS_ID=" ";
if [ -n "${SERVER})" ]
then
while read LINE
do
if [ `echo ${LINE} | cut -c1` != "#" ]
then
DIR=`echo ${LINE} | cut -f1 -d"|"`;
cd $DIR
SCRIPTNAME=`echo ${LINE} | cut -f2 -d"|"`;
ISEXECUTABLE=`echo ${LINE} | cut -f3 -d"|"`;
DESC=`echo ${LINE} | cut -f4 -d"|"`;
fi
if [ -n "${SCRIPTNAME}" ]
then
CURRENT_PROCESS_ID=`ps -ef | grep "${SCRIPTNAME}" | grep -v grep | grep "${USER}" | grep "1" | tr -s ' ' ' ' | cut -c2- | cut -f2 -d" "`;
if [ -z "$CURRENT_PROCESS_ID" ]
then
cd ${DIR}
exec $SCRIPTNAME;
RET=$?;
if [ "${RET}" -eq 0 ]
then
NEW_PROCSS_ID=`ps -ef | grep "${SCRIPTNAME}" |grep -v grep | grep "${USER}" | grep "1" | tr -s ' ' ' ' | cut -c2- | cut -f2 -d ""`;
if [ -z "$NEW_PROCSS_ID" ]
then
echo "$SCRIPTNAME has successfully started with ProcessID ${NEW_PROCESS_ID}" >> $LOG_FILE
mailx -s "$USER instnce of $SCRIPTNAME restarted with ProcessID $NEW_PROCSS_ID" test@xyz.com
fi
fi
fi
echo "$SCRIPTNAME is already running with $CURRENT_PROCESS_ID SPID" >> ${LOG_FILE};
fi
done < /GEM_PILOT/custom/script/test.dat;
fi