[Solved] How to stop script at certain condition?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to stop script at certain condition?
# 1  
Old 01-17-2014
[Solved] How to stop script at certain condition?

Hi Gurus,

my script likes below
Code:
if [condition];then
    if [condition1]; then
       exit 30
    fi
if
 for loop
do
done

I want to if condition1 is true, it exit the execution the script completely with error code 30. but right now it still exe for loop.
I try to add below
Code:
if [condition];then
    if [condition1]; then
       exit 30
    fi
var=`echo $?`
if var!=0
exit 30
fi
if
 for loop
do
done

but the echo $? give me 0 even the condition1 is not true.

anybody inputs are welcome

thanks in advance
# 2  
Old 01-17-2014
The code you have posted is syntactically wrong. And the exit you've used is not in a loop. Please post the actual code.
# 3  
Old 01-17-2014
Quote:
Originally Posted by Scott
The code you have posted is syntactically wrong. And the exit you've used is not in a loop. Please post the actual code.
Thanks for your relay. I found the issue. the issue is I put comment for that line.
# 4  
Old 01-17-2014
OK, thanks for letting us know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Help with condition

I have below code, I am checking on one server where ppp.sh process not running it is perfectly fine, when i am checking the same script on another server where ppp.sh script is running, it is throwing error "too many arguments", how to avoid this. If i will check on server where process running it... (5 Replies)
Discussion started by: learnbash
5 Replies

2. Shell Programming and Scripting

[SOLVED] Sorting file and get everything on same line on condition

Good afternoon! I am a perl newbie. I hope you will be patient with me. I have a script that needs to be written in perl. I can't do it in awk or shell scripting. Here is the script: #!/usr/bin/perl use POSIX qw(strftime); use FileHandle; use Getopt::Long; use IO::Handle;... (0 Replies)
Discussion started by: brianjb
0 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Delete files with condition

I have a directory containing thousands of items “video files”, these items were generated by an application, which generates two items with the same name but with different extensions “.avi and .mp4”. There was a tool in my application to remove one item @ a time. Later I found this tool removes... (5 Replies)
Discussion started by: awadeid
5 Replies

4. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

5. UNIX for Advanced & Expert Users

rc.d script to stop not workign

I have a simple script that I have put in all the rc.d directories from 1-6 and have named it K20blah and S20blah .I am on red hat linux and I see that when i do reboot the S20blah is ignored but the K20blah is executed during startup . Any suggestions? #! /bin/sh # /etc/init.d/blah # #... (3 Replies)
Discussion started by: gubbu
3 Replies

6. Shell Programming and Scripting

Stop execution of script if some condition fails

After my if condtion give rusult true then script should stop execution. Please advice...Thnaks in advance (1 Reply)
Discussion started by: vivek1489
1 Replies

7. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

8. UNIX for Dummies Questions & Answers

Stop a shell script

Hi, I am writing a bash shell script. How can I tell it to stop. For example, I would like to have something similar to the following: mike=1 if ; then STOP THE SCRIPT fi (3 Replies)
Discussion started by: msb65
3 Replies

9. Shell Programming and Scripting

Script does not stop when doing a read

Hi Folks, I have been trying to create a script wherein after it reads a certain number of data, it will pause and ask the user if he wants to continue or not. However, it seems that when it is supposed to read the user's answer, the script will go into a loop. What is wrong with my script here?... (7 Replies)
Discussion started by: rooseter
7 Replies

10. UNIX for Dummies Questions & Answers

Start/Stop Script

I'm a newbie to the Unix world Help! I have to maintain a host of Sybase database servers sitting on Unix Sun Solaris 8...I've been tasked with finding/creating a way to auto start/stop Unix via unix commands, specifically when the Unix servers need to be restarted we want Sybase to start... (2 Replies)
Discussion started by: jjv1
2 Replies
Login or Register to Ask a Question