do nothing if condition is not met but not exit

Hello all, I created the below script....and it seemed to be working fine. My problem is i want the script to ignore rest of the things if my condition is not met but do not exit....

#!/bin/ksh
###########################
###########################

# Set name of the listener, this need to be upper or lower case
#LSNR=$1

echo "`basename $0` Start `date`."
for LSNR in $*
do

RM="rm -f"

echo "Listener name: $LSNR"

export user_id=`whoami`
export ORACLE_HOME=`ps -ef|grep tnslsnr|grep -v grep|grep -v sed|grep $user_id|grep $LSNR|awk '{print $8}'|uniq|sed "s#/bin/tnslsnr##g"`
export PATH=$ORACLE_HOME/bin:$PATH;

#check who owns the listiner
lsnr_ownr=`ps -ef|grep tnslsnr|grep -v grep|grep $LSNR|awk '{print $1}'|uniq`

if test $lsnr_ownr = $user_id; then
echo "Listener $LSNR is being ran as $lsnr_ownr owner"
else
echo "Listener $LSNR is owned by a different user -- aborting script"
echo "Run script using $lsnr_ownr user"
exit
fi

more cmd
more cmd
more cmd....
exit

so for above if $lsnr_ownr = $user_id; then it echo out something.... but if its NOT then it echo out something and EXIT.....

i do not want it to exit...just do nothing for rest of the script(more cmd, more cmd)....so how can i have it do nothing for rest of the script and exit out at very end after the more cmd ???

U may use some flag, set it as needed and use it to run last command OR not to run.

 
.
.
flag="N"
if test $lsnr_ownr = $user_id; then
echo "Listener $LSNR is being ran as $lsnr_ownr owner"
flag="Y"
else
echo "Listener $LSNR is owned by a different user -- aborting script"
echo "Run script using $lsnr_ownr user"
fi
 
if [ $flag="Y" ]; then
more cmd
more cmd
more cmd....
fi
exit
 

OR code lines can be adjusted as below:

 
.
.
.
if test $lsnr_ownr = $user_id; then
echo "Listener $LSNR is being ran as $lsnr_ownr owner"

more cmd
more cmd
more cmd....

else
echo "Listener $LSNR is owned by a different user -- aborting script"
echo "Run script using $lsnr_ownr user"
fi
exit
1 Like

by the way this can save you some numerous |

lsnr_ownr=$(ps -ef | nawk -v O="$ORACLE_SID" '($0~O)&&/[t]nsl/{print$1}')
ORACLE_HOME=$(ps -eaf | sed -n '/'"$ORACLE_SID"'.*[t]nsl/{s:/bin/tns.*::;s:[^/]*::;p;}')
1 Like