do nothing if condition is not met but not exit


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting do nothing if condition is not met but not exit
# 1  
Old 12-15-2010
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....



Code:
#!/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 ???

Last edited by radoulov; 12-15-2010 at 12:27 PM.. Reason: Code tags, please!
# 2  
Old 12-15-2010
U may use some flag, set it as needed and use it to run last command OR not to run.

Code:
 
.
.
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:
Code:
 
.
.
.
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


Last edited by anurag.singh; 12-15-2010 at 01:03 PM..
This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 12-15-2010
by the way this can save you some numerous |

Code:
lsnr_ownr=$(ps -ef | nawk -v O="$ORACLE_SID" '($0~O)&&/[t]nsl/{print$1}')

Code:
ORACLE_HOME=$(ps -eaf | sed -n '/'"$ORACLE_SID"'.*[t]nsl/{s:/bin/tns.*::;s:[^/]*::;p;}')


Last edited by ctsgnb; 12-15-2010 at 03:08 PM..
This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk - print when condition is met

I have a file.txt containing the following: Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT Length=100 Score E Sequences producing significant alignments: (Bits) Value ... (2 Replies)
Discussion started by: tons92
2 Replies

2. Shell Programming and Scripting

Add another condition to bash for when not met

In the below I can not seem to add a line that will add Not low if the statement in bold is not true or meet. I guess when the first if statement is true/meet then print low, otherwise print Not low in $(NF + 1). I am not sure how to correctly add this. Thank you :). if(low <= $2 && $2 <=... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Need help on how to append on the filename when condition met.

Hi All, Seeking for your assistance on how to append the specific string when $3 condion met. ex. file1.txt ar0050046b16,5,888,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 expected output:... (5 Replies)
Discussion started by: znesotomayor
5 Replies

4. Shell Programming and Scripting

Getting the records once condition met

Hi All, Seeking for your assistance to get the records once the $2 met the condition. Ex. file 1.txt 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 123232,11-Aug-2015 08:33:37 PM,4234324,1321432,34364 Output: 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 What i did... (5 Replies)
Discussion started by: znesotomayor
5 Replies

5. Shell Programming and Scripting

Awk. Abort script if condition was met.

I want to abort script if input variable matched first field in any line of a file. #!/bin/sh read INPUTVAR1 awk "{if(\$INPUTVAR1 == $1) x = 1} END {if(x==1) print \"I want to abort script here\"; else print \"OK\"}" /etc/some.conf I tried "exit" and system("exit") but no luck. (1 Reply)
Discussion started by: urello
1 Replies

6. Shell Programming and Scripting

Delete if condition met in a column

i have a table like this: id, senderNumber, blacklist ----------------------------- 1 0835636326 Y 2 0373562343 Y 3 0273646833 Y and I want to delete automatically if a new inserted row on another table consist anything on senderNumber column above using a BASH Script I... (9 Replies)
Discussion started by: jazzyzha
9 Replies

7. Shell Programming and Scripting

perl -Calling the Subroutine Only if the condition is met

Hello All, I am in the process of learning perl.I have a perl script and based on the arguments passed it would the appropriate subroutine that is defined in the script. Now, I need to check a value that is defined in the Environment variables and should call the subroutine only if the... (1 Reply)
Discussion started by: filter
1 Replies

8. UNIX for Advanced & Expert Users

While loop only if a condition is met

All, I wrote the following section of code (which logically in PHP would of worked): tmpPATH=${1} tmpTAG=${2} if then while read tmpTAG tmpPATH do fi echo $tmpTAG echo $tmpPATH if then done < ./config.cfg fi (4 Replies)
Discussion started by: Cranie
4 Replies

9. UNIX for Dummies Questions & Answers

While loop seems to exit when blank line is met

Hello everyone! I am having an issue with a script I am trying to create. I have an input file (named sort_$1.txt) like: aaaa bbbb cccc dddd eeee and I process it with the following code: while read -r EachLine2 do (11 Replies)
Discussion started by: haaru
11 Replies

10. Shell Programming and Scripting

How to break a loop if condition is met

I am having trouble figuring this code I want to grep a text from a file and if it match certain text it break out of the loop or it should continue searching for the text Here is what I have written but it isn't working while true f=`grep 'END OF STATUS REPORT' filename` do if ... (9 Replies)
Discussion started by: Issemael
9 Replies
Login or Register to Ask a Question