Sponsored Content
Top Forums Shell Programming and Scripting How to restart the same step when return value is not equal to zero? Post 302895866 by reignangel2003 on Thursday 3rd of April 2014 04:17:20 AM
Old 04-03-2014
How to restart the same step when return value is not equal to zero?

Hi Again Guru's

One of the requirements for the shell script is that when the return value of a given function is not equal to zero, it should have the option for the user to re-execute the function that has failed.

Example:
the script has different functions:
func_1()
func_2()
func_3()
func_4()
....


when func_1 fails, it should ask the user to make some necessrary corrections and once done, it should re-execute that same function.

Any idea will help.

below is the sample code.
Code:
#!/usr/bin/sh

#Function to get return value
func_getRetValue()
{
retValue=$?

if [ $retValue -gt 0 ]
then
   echo "Encountered ERROR"
	
	func_pause "Press any key when ready ..."
else
   echo "NO ERROR FOUND"
	
	func_pause "Press Any key to continue..."
	
fi

}

#function to wait for the user's prompt before proceeding
func_pause()
{
   read -p "$*"
}

#Function to check if supplemental logging is enabled in Aexeo Database
func_enableSupplementalLoggingOnAexeoDB()
{

sqlplus -s ${userName}/${password}@//${hostname}/${oraInstance} <<EOF > ${logDir}/output.out
	set heading off
	SELECT  SUPPLEMENTAL_LOG_DATA_MIN from v\$database;
EOF

#Check the output of the sql statement if it is "YES"
#if not run sql statemet to alter the table

status=`cat ${logDir}/output.out | sed '/^$/d' | tail -3`

if [ $status == "YES" ]
then
     echo "Minimal supplemental logging is enabled in Aexeo Database"
	 echo "Status is ${status}"
elif [ $status != "YES" ]
then
    echo "Supplemental logging is not enabled"
	echo "Please login to Database and set SUPPLEMENTAL_LOG_DATA_MIN to \"YES\" "
fi

#func_pause "Once corrected press any key to continue ..."
}

func_createPartitionsVPDUsers()
{
   
}

#-----------------
# Main
#-----------------

step="${1:-0}"

while :
do
   case $step in
      0) : ;;
      1) echo "Running Step 1 : Check supplemental logging in Aexeo Database is enabled"
	     func_enableSupplementalLoggingOnAexeoDB
		 
		 
		 retValue=$?
		 
		 if [ $retValue -gt 0 ]
		 then
		    echo "Encountered ERROR"
			
			func_pause "Press any key when ready ..."
		 else
		    echo "NO ERROR FOUND"
			
			func_pause "Press Any key to continue..."
			
		 fi
	  
	  ;;
	  2) func_createPartitionsVPDUsers 
	  
	  ;;
      *) exit ;;
   esac
   
   ((step=${step} + 1))
done

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

install of sco unix step by step

HI I am new to unix and need to install sco unix on a new server - could anybody help me with the steps I need to take - the hd is a 9gb scsi drive (pretty old machine) Thanks (1 Reply)
Discussion started by: porikamu
1 Replies

2. UNIX for Dummies Questions & Answers

Step by step Installation of Unix SCO 2.1

I am new to unix and server at my job crashed due to hardware problem. I'm now opted to install sco unix on a new server - could anybody help me with the steps I need to take (pretty old machine) Thanks & Regards Nancy :( (0 Replies)
Discussion started by: nensee7
0 Replies

3. Shell Programming and Scripting

works step by step on command line but not in script

Hi all, The following script is fine when I work via command line m=1 c=0 while do echo $m gnokii --getsms IN $m > out.txt; m=`expr $m + 1`; cat out.txt >> message_log; ############ read first crap< <(sed -n '/Text:/{n;p;}' out.txt); read message< <(sed -n '/Text:/{n;p;}'... (2 Replies)
Discussion started by: whamchaxed
2 Replies

4. Linux

May you explain step by step where and how I will add pseudo code

Thank all of you. May you explain step by step where and how I will add pseudo code Note : I have Linux 2.6.24-26-server on x86_64 dears kindly help me (3 Replies)
Discussion started by: nonowa
3 Replies

5. UNIX for Advanced & Expert Users

Test shell script step by step?

Hi to all, I don't know if someone has done sometime a MS Excel Macro, that allows us to press F8 over the code to see step by step, to mention something, how is running the code, which values take the variables, if some loop is executing correct or where a error occurs, and some other... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

6. Solaris

step step apache2 configuration doc

Hi Guys, does anyone know of a step by step guide on how configure apache2 web server in solaris 10? I will really appreciate it. Thanks a lot (1 Reply)
Discussion started by: cjashu
1 Replies

7. What is on Your Mind?

Slowly Removing Bold Font Style - Step-by-Step

FYI, I'm slowly removing a lot of the bold font-styles from titles of discussions, forum titles, etc I'm not removing bold for the entire site because we do need bold from time to time, especially in posts and sometimes in other places. However, the original forum style had way too much... (3 Replies)
Discussion started by: Neo
3 Replies
NPM-RUN-SCRIPT(1)														 NPM-RUN-SCRIPT(1)

NAME
npm-run-script - Run arbitrary package scripts SYNOPSIS
npm run-script <command> [--silent] [-- <args>...] alias: npm run DESCRIPTION
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[-script] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts. As of ` https://blog.npmjs.org/post/98131109725/npm-2-0-0, you can use custom arguments when executing scripts. The special option -- is used by getopt https://goo.gl/KxMmtG to delimit the end of the options. npm will pass all the arguments after the -- directly to your script: npm run test -- --grep="pattern" The arguments will only be passed to the script specified after npm run and not to any pre or post script. The env script is a special built-in command that can be used to list environment variables that will be available to the script at run- time. If an "env" command is defined in your package, it will take precedence over the built-in. In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package, you should write: "scripts": {"test": "tap test/*.js"} instead of "scripts": {"test": "node_modules/.bin/tap test/*.js"} to run your tests. The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. The actual shell referred to by /bin/sh also depends on the system. As of ` https://github.com/npm/npm/releases/tag/v5.1.0 you can customize the shell with the script-shell configuration. Scripts are run from the root of the module, regardless of what your current working directory is when you call npm run. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install, just in case you've forgotten. You can use the --silent flag to prevent showing npm ERR! output on error. You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. SEE ALSO
o npm help 7 scripts o npm help test o npm help start o npm help restart o npm help stop o npm help 7 config January 2019 NPM-RUN-SCRIPT(1)
All times are GMT -4. The time now is 11:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy