👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Return code is "0" though the command fails.

Tags
mtime

👤 Login to reply

 
Thread Tools Search this Thread
# 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 to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using "mailx" command to read "to" and "cc" email addreses from input file asjaiswal UNIX for Dummies Questions & Answers 2 10-11-2014 09:32 PM
Crontab -e command return "413" roadmanjim UNIX for Dummies Questions & Answers 2 09-19-2011 07:58 AM
Unix "look" Command "File too large" Error Message shishong UNIX for Dummies Questions & Answers 14 05-30-2011 03:47 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
Command Character size limit in the "sh" and "bourne" shell Roshan1286 Shell Programming and Scripting 1 10-29-2009 07:38 AM
Command Character size limit in the "sh" and "bourne" shell Roshan1286 UNIX for Advanced & Expert Users 1 10-29-2009 07:01 AM
Command Character size limit in the "sh" and "bourne" shell Roshan1286 UNIX for Dummies Questions & Answers 1 10-29-2009 07:01 AM
Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error mes linuxbee UNIX for Dummies Questions & Answers 3 05-14-2009 04:00 PM
return code capturing for all commands connected by "|" ... new_learner UNIX for Dummies Questions & Answers 6 12-16-2008 04:58 AM
#!/bin/sh script fails at StringA | tr "[x]" "[y]" by_tg UNIX for Dummies Questions & Answers 3 02-22-2008 11:17 AM


All times are GMT -4. The time now is 02:27 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password