Return code is "0" though the command fails.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Return code is "0" though the command fails.
# 1  
Old 01-14-2009
Return code is "0" though the command fails.

The return code is "0" though the command fails. How to get a return code of "1" for this command when it fails or modify the command to get the right return code?

On HP UNIX

#-------- SCRIPT ----
#!/bin/ksh
find /opt/oracle/oroem/product/10.2.0.4/rdbms/audit/ \( -name "*.aud" \) -mtime +1 -exec rm -f {} \;
echo "Return Error Code" $?


------------------OUTPUT-------------
> b.sh
rm: /opt/oracle/oroem/product/10.2.0.4/rdbms/audit/ora_12289.aud not removed. Permission denied
Return Error Code 0
# 2  
Old 01-14-2009
The return you get (0) is from find(1). To obtain the return code from rm(1) you could try running the command in a for loop.
Code:
$ for f in $(find......); do echo $f; rm -f $f; echo $?; done

# 3  
Old 01-14-2009
Quote:
Originally Posted by agn
The return you get (0) is from find(1). To obtain the return code from rm(1) you could try running the command in a for loop.
Code:
$ for f in $(find......); do echo $f; rm -f $f; echo $?; done


That will fail if any filenames contain spaces.
# 4  
Old 01-20-2009
Quote:
Originally Posted by cfajohnson

That will fail if any filenames contain spaces.
Your suggestion works.
Thank You.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. UNIX for Dummies Questions & Answers

Crontab -e command return "413"

I was trying to edit the crontab file for root. I had saved off the existing file for later recovery. When I typed crontab -e to edit, the system returned "413" and the cursor stopped blinking. Ctrl+c stopped that. I typed, in bash, "EDITOR=vi" (Enter). Then, "export EDITOR" (Enter). Then,... (2 Replies)
Discussion started by: roadmanjim
2 Replies

3. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error mes

I would like to know what means this error and how to fix it Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error message Thank you (3 Replies)
Discussion started by: linuxbee
3 Replies

9. UNIX for Dummies Questions & Answers

return code capturing for all commands connected by "|" ...

Hi, While I am using "|" to join multiple commands, I am not getting the return code when there is error in one of the commnads. Eg: b=`find /path/a*.out | xargs basename` if ; then echo "Error" fi if there is error while finding the file or getting the basename, the $? is... (6 Replies)
Discussion started by: new_learner
6 Replies

10. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign. This is not working. There are spaces between each component: $StringA | tr "" "" The error returned is: test: Specify a parameter with this command Can you help? (3 Replies)
Discussion started by: by_tg
3 Replies
Login or Register to Ask a Question