Passing exit code to calling script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing exit code to calling script
# 1  
Old 09-15-2006
Passing exit code to calling script

In production I need to pass an exit code from a script that is being called 3 or 4 layers deep. I've created test scripts to play with it until I get it right. As you can tell, this is not my normal job. Perhaps I should have entered this in UNIX for Dummies section. Anyway, I keep losing the value of my variable. Can you please help? Thanks.

SCRIPT 1

#!/usr/bin/ksh
echo 'in test1'
EXITSTATUS=$?
if test2 [${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT 2

#!/usr/bin/ksh
echo 'in test2'
EXITSTATUS=$?
if test3 [${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT3

#!/usr/bin/ksh
echo 'in test3'
EXITSTATUS=99
# 2  
Old 09-15-2006
try something like this:
Code:
#!/usr/bin/ksh
echo 'in test1'
EXITSTATUS=0
test2
EXITSTATUS=$?
if  [ ${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT 2

#!/usr/bin/ksh
echo 'in test2'
EXITSTATUS=0
test3
EXITSTATUS=$?
if  [ $EXITSTATUS -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT3

#!/usr/bin/ksh
echo 'in test3'
EXITSTATUS=99
exit $EXITSTATUS

# 3  
Old 09-18-2006
Thank you. I appreciate your help. It's working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

2. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

3. Programming

Gcc error when calling exit(-1) in a .c file

gcc is giving me an error when calling exit(-1) in xbuplot.c cd ../pltlib; make xbuplot.o make: Entering directory `/media/ios120/chrisd/research/fast-zb/fast/pltlib' gcc -c -o xbuplot.o xbuplot.c xbuplot.c: In function ‘xbuinit_': xbuplot.c:171:5: warning: incompatible implicit... (5 Replies)
Discussion started by: kristinu
5 Replies

4. Shell Programming and Scripting

PERL script -- calling 'sed' by passing 'variable value'.

Hi Friends, I'm calling 'sed' command inside one perl script, which is to list directory names which are having some date value as their names (in the form YYYYMMDD) with in the range (start and end date). #!/usr/bin/perl -w use strict; use warnings; my $DATA = "/export/home/ganapa"; my... (5 Replies)
Discussion started by: ganapati
5 Replies

5. Shell Programming and Scripting

Setting script exit code

#!/bin/ksh row=`sed '1!G;h;$!d' file1.xml | head -2| tail -1` echo "$row" | awk -F"" '{$esum=$5}' row=`sed '1!G;h;$!d' file2.xml | head -2| tail -1` echo "$row" | awk -F"" '{$isum=$5+$19}' echo "Exp:$esnum" echo "Imp:$isum" if then echo "Matched" else echo "Not matched" fi ... (6 Replies)
Discussion started by: skyineyes
6 Replies

6. Shell Programming and Scripting

how to exit out of the calling Shell Script

Hi All, I tried looking for this, but was not able to get a clear answer. Hence posting here. Please find the details below. Thanks for the help I have 2 shell scripts, script1.sh and script2.sh. I call script2.sh from within script1.sh ( by simple ./script2.sh command). Based on some... (7 Replies)
Discussion started by: harimac
7 Replies

7. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

8. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

9. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

10. Shell Programming and Scripting

Passing a parameter while calling a script

Hello everyone I was asked to pass a parameter in the calling of a script. IŽll have two parameters London and Birmingham and IŽll need to pass this because each of these will have a specific script however with the same name. /home/script/loaddata.ksh Lond /home/script/loaddata.ksh Birm... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies
Login or Register to Ask a Question