I would like to stop all process if any of the script got errors?. If for example script1 works fine will continue script2, then if the script2 got errors, The bash should stop and will no continue to script3.
If it issues a return code, this will be in the variable $? until you do something else. You can test for that:-
You can make your script exit with a non-zero return code by putting in exit 5 or whatever integer value you want (within reason)
Another way to do this is to make them dependant on each other with the && operator. This will move to the next if the return code is zero but quit that statement (carries on the the overall script) if any one of them fails:-
Do either of these meet your needs?
-e Exit immediately if a pipeline (which may consist of a single simple command), a list, or a compound command (see SHELL GRAMMAR above), exits with a
non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of
the test following the if or elif reserved words, part of any command executed in a && or || list except the command following the final && or ||, any
command in a pipeline but the last, or if the command's return value is being inverted with !. If a compound command other than a subshell returns a
non-zero status because a command failed while -e was being ignored, the shell does not exit. A trap on ERR, if set, is executed before the shell
exits. This option applies to the shell environment and each subshell environment separately (see COMMAND EXECUTION ENVIRONMENT above), and may cause
subshells to exit before executing all the commands in the subshell.
Hi Team,
I my script i telent my node ip and after loging i run some commands...But some time login fail so i want to stop script at that time..
CONFIG_CHNG.sh
printf 'Please Input Node ID : '
read node
node="$node"
#exec > node_log_$node.log 2>&1
#set -x
>... (2 Replies)
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)
Hi All,
I have a requirement where if Source Count is not equal to Target count, then I need to exit/abort the script and come out. Then send an email to thummi@email.com saying "RECORD COUNT DOES NOT MATCH. Please need your help.
Here is what I have written : If even the count is not... (1 Reply)
Hi,
In my shell script I use the following code to copy files from one directory to other.
for file in `ls`; do
#----------------- Copy Files From INDIR to OUTDIR -------------#
echoen "Copying File ${INDIR}/$file to ${OUTDIR}/${file}"
cp ${INDIR}/$file ... (4 Replies)
Below is my shell script from which I am trying to invoke few Hive SQL queries and the below shell script works fine.
Problem Statement:-
If you see my first `hive -e` block in the below shell script which contains a very long Hive SQL query. Sometimes that Hive SQL query gets failed due to... (1 Reply)
Hi
I have written a script which returns a number. This resulting number I assign to the variable for example:
$ A=`get_dbnum 118 ttrn`
$ echo ${A}
8208
$
The script becomes interective once the error occures and the number is not found. It prompts the user to enter the number. The... (1 Reply)
I have a little bash script that includes make to compile with g++ and then a statement to actually run the compiled program. When it (the script) gets a syntax error, it does not abort and continues to run the previous version of the program.
How can I make the script abort when g++ generates a... (1 Reply)
HI All,
I am working on Solaris 8, i have this application runing on one of the partitions,(the installation was done here ie /export/home)
And the out put of this goes to another parition of other disk attached to the same machine. After a certain period of time is get this error stating... (2 Replies)