exit in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting exit in unix
# 1  
Old 05-19-2010
exit in unix

I am fixing a production issue. I am running out some problems with the exit command.
This is how the code was in production

Code:
if [ "$ubnd" -le 0 ]; then
        echo 1 > $tmp/b1stat
        exit 1
else
        echo 0 > $tmp/b1stat
fi

I wanted to check for another condition and set a value 3 to the file and exit..

I am trying like this,

Code:
if [ "$ubnd" -le 0 ]; then
    if [ $traceflag -eq 1 ] ;then
        echo 3 > $tmp/b1stat
        exit 1                     ----> This is the issue
    else
        echo 1 > $tmp/b1stat
        exit 1
    fi
else
   echo 0 > $tmp/b1stat
fi

It gives me error when I added the new exit condition. Can anyone advise what am I missing.. I am not clear with the exit codes..
# 2  
Old 05-19-2010
I can't see any error, see the code and output below; please post the error message. Also add a set -x at the beginning of that block and a set +x at the end of this block.

Code:
$> cat mach.ksh
ubnd=0
traceflag=1
tmp=.

if [ "$ubnd" -le 0 ]; then
    if [ $traceflag -eq 1 ] ;then
        echo 3 > $tmp/b1stat
        exit 1
    else
        echo 1 > $tmp/b1stat
        exit 1
    fi
else
   echo 0 > $tmp/b1stat
fi
$> ./mach.ksh
$> ll b1stat
-rw-r--r-- 1 root root 2 19. Mai 08:52 b1stat



---------- Post updated at 09:01 AM ---------- Previous update was at 08:54 AM ----------

Oh and you could write exit 1 once below the if/else/fi since both branches result in it.
# 3  
Old 05-19-2010
This is a web application. Whenever I have that exit command, it gives "internal server error". I modified the code as

Code:
if [ "$ubnd" -le 0 ]; then
    if [ $traceflag -eq 1 ] ;then
        echo 3 > $tmp/b1stat
    else
        echo 1 > $tmp/b1stat
    fi
    exit 1
else
   echo 0 > $tmp/b1stat
fi

When I comment the exit 1 statement, it works fine...Even when I have exit 1 as in my 1st post, it works good. But it fails when I have something like above..
# 4  
Old 05-19-2010
Just a try - if you change the exit 1 vs an exit 0, does the error still display on your webserver?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Pipe -Exit when there are no bytes to read

Hi All, I'm creating a program which reads millions of bytes from the PIPE and do some processing. As the data is more, the idea is to read the pipe parallely. Sun Solaris 8 See the code below: #!/bin/sh MAXTHREAD=30 awk '{print $1}' metadata.csv > nvpipe & while do ... (3 Replies)
Discussion started by: mr_manii
3 Replies

2. Shell Programming and Scripting

Make expect exit the UNIX script in erreneous condition

Hi, I am writing a menu driven program using shell script. THe script will be collecting data by logging into the other servers and bringing back the data to home server to process it and accordingly issue commands. TO automate commands execution , I am using expect script. However I am not able... (5 Replies)
Discussion started by: ashima jain
5 Replies

3. UNIX for Dummies Questions & Answers

UNIX exit code 11

We have a batch Unix process that runs during the day and it is getting an exit code 11 from Unix. It finishes a sqlplus step and gets the exit code 11 before it starts the next step. This used to happen once a year and now is happening more often (but not every time the process runs). We have... (2 Replies)
Discussion started by: msol
2 Replies

4. Shell Programming and Scripting

How to exit a shell script if a unix command does not return any value for 10 seconds?

Hi, Can anyone help me how to exit a shell script if a unix command inside does not return any value for 10 seconds? The scenarios is like this. I want to login to a application using shell script where the connection string is mentioned.but suppose this connection string is not... (10 Replies)
Discussion started by: arijitsaha
10 Replies

5. Shell Programming and Scripting

Exit code from piping in unix shell script

Hi , I have following code in my shell script : "$TS_BIN/tranfrmr" "${TS_SETTINGS}/tranfrmr_p1.stx" "${TS_LOGS}/tranfrmr_p1.err" | ( "$TS_BIN/cusparse" "${TS_SETTINGS}/cusparse_p2.stx" "${TS_LOGS}/cusparse_p2.err" | ( "$TS_BIN/tsqsort" "${TS_SETTINGS}/srtforpm_p3.stx"... (8 Replies)
Discussion started by: sonu_pal
8 Replies

6. UNIX for Dummies Questions & Answers

Problem in Unix script to exit from Putty

We have a requirement where in the user needs to select a option 4 from the menu and the putty window should be closed.I tried giving exit 0 ;; and this is only exiting from the script menu and showing back the prompt.Is there a way for this. (2 Replies)
Discussion started by: gopalt
2 Replies

7. Shell Programming and Scripting

exit from unix

Hi All, How can i exit from "unix"?. Looks silly , but still , i logged in to the unix box , then i did a "su - other user" , then " su - other user" , and i end up in the unix as a some 10th user. If i exist i will come to the previous user/account. I want to exit from unix in a single shot. ... (2 Replies)
Discussion started by: panyam
2 Replies

8. Programming

exit status running java classpath in unix shell

I have a java classpath running inside of a unix shell script. During my testing it will error with lines that show an example like this below. java.io.FileNotFoundException error at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:129), ... (2 Replies)
Discussion started by: mmcds
2 Replies

9. UNIX for Dummies Questions & Answers

exit unix, but says running jobs

hi, i give a exit to the system, but it says that i have running jobs... so i do a ps and it displays two lines, one is a -ksh and the other is the ps which i am issuing... then i give a who -uH, find my pts.. then do a grep... still the same..... whats wrong.. (6 Replies)
Discussion started by: yls177
6 Replies

10. Programming

How to find the exit status of last command in Unix?

Hi, I want to find the exit status of the last executed command in C Shell. Tried $? but getting the error Variable syntax...$? does not seem to work in C shell.. is there any other command in C shell to find the exit status of last command? Thanks in advance, raju (1 Reply)
Discussion started by: rajugp1
1 Replies
Login or Register to Ask a Question