exit status depending on output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers exit status depending on output
# 1  
Old 04-14-2009
exit status depending on output

Hi

I have a script that does a select from a table. I want the script to return a 0 status if a specific column has 'OK' value or return 1 if this column returns 'NOT OK'.

The output now is similar to:
COL1 COL2 STATUS
------- --------- -------

I want to be limited to an exit value:

Whenver STATUS has NOT OK, it returns 1
If not, return 0


how to achieve this?

thanks
# 2  
Old 04-14-2009
Code:
$ echo -e "Test\tTest\tNot OK"
Test    Test    Not OK
$ echo -e "Test\tTest\tNot OK"|grep -qv "Not OK$" ; echo $?
1
$ echo -e "Test\tTest\tOK"|grep -qv "Not OK$" ; echo $?
0

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return value to shell script, depending on status of pl/sql udpate

Hi All, I need to return value to the main shell script, depending on whether the UPDATE command in the embedded pl/sql is successfu or not. #!bin/ksh updateStatus=`sqlplus --conn details-- << EOF DECLARE var_rows NUMBER; BEGIN update table_name set column_name =... (7 Replies)
Discussion started by: rituparna_gupta
7 Replies

2. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

3. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

4. UNIX for Dummies Questions & Answers

Processes and exit status

Hi, I can't understand why the last $? is 1? can somebody plz help me to understand it? thanks $ ksh $ ps -f UID PID PPID C STIME TTY TIME COMMAND msarabad 12361 12319 0 15:17:58 pts/1 0:00 ksh msarabad 12319 12317 0 15:15:11 pts/1 0:00 -sh msarabad 12362 12361 ... (7 Replies)
Discussion started by: messi777
7 Replies

5. Shell Programming and Scripting

Exit status redirection

Hi, I'm having this simple code below, the file serverlist has a list of IPs one per line. When executed the while loop is executed only once, after that the program terminates. How should i redirect the exit status, so that the entire list of IP will get executed? #!/bin/bash exec <... (4 Replies)
Discussion started by: agent001
4 Replies

6. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

7. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

8. UNIX for Dummies Questions & Answers

exit status conditions

Hi all, i am writing a script to test if some servers are down and prompt if test positive. i used rlogin and rsh then exit but the script when run, logs into the servers and stays. pls what can i do to salvage this? or what other options do you suggest? (6 Replies)
Discussion started by: sdcoms
6 Replies

9. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies

10. UNIX for Dummies Questions & Answers

tar exit status

I am using tar to backup files to tape. When the tape is full, I'm prompted for a second tape and told to press enter when ready. When I press enter, tar stops and gives an exit status of 5. Does anyone know what this indicates? Also, if everything fits on one tape and the backup... (3 Replies)
Discussion started by: thorndike
3 Replies
Login or Register to Ask a Question