return status after run the shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting return status after run the shell script
# 1  
Old 10-13-2009
return status after run the shell script

Hello, I wanted to delete all files which are placed 14 days back. Here is my below script. My script works very well and it deletes all files 14 days back.

I wanted to display message incase if the delete script is not successful. The below script returns always successful. But the directory /ods/apps/report/download/archive/archive/xxx is wrong one. How can i trap if there is any failure...


Code:
find /ods/apps/report/download/archive/archive/xxx -name "*txt*" -mtime +13 -exec rm -f {} \;
find /ods/apps/report/download/archive/archive/ -name "*TXT*" -mtime +13 -exec rm -f {} \;
if [ $? -ne 0 ];
then
echo "NOT SUCCESSFUL"
else
echo "SUCCESSFUL"
fi


Last edited by vgersh99; 10-13-2009 at 01:42 PM.. Reason: code tags, PLEASE!
# 2  
Old 10-13-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 10-13-2009
Hello, I am sorry about not following guidelines. I will follow for future posting.
I am sorry for inconvenience. I would appreciate if any one can help me on this.
# 4  
Old 10-13-2009
You have to check the $? everytime, and not at the end.

Say if you want to check the first find execution status, do it immediately after the first find execution. Not at the end...
# 5  
Old 10-13-2009
I got it. Thank you very much.
# 6  
Old 10-14-2009
Wrench

Here is another possible solution:
Code:
set -e   # the script will exit immediately if one
           # of the following commands will return
           # a non-zero status (be cautious using it in other scripts)

trap "echo FAILED >&2" ERR # will print the word 'FAILED' to /dev/stderr
                                      # if the script will exit with an error

...your find commands ...

echo "SUCCESSFULL" >&2   # print 'SUCCESSFULL' to /dev/stderr
                                     # if we managed to reach the end of the script

Here you don't need to repeat exit status check after each invocation of 'find' command.
# 7  
Old 10-20-2009
Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Inner script run and its exit status

Main Script #!/bin/ksh echo "Maimn script" ./clocal/www/web-data/WAS/WebSphere7/scripts/DealerLocator/Scripts/secondscript.ksh echo "$? = status" Sdecond Script #!/bin/ksh echo "In second SCript" exit 1 Output: Maimn script ./testmain.ksh:... (4 Replies)
Discussion started by: dineshaila
4 Replies

3. Shell Programming and Scripting

Shell script has to run until the status value is updated

Hi All, Need some help like how to exit from the script after updating the column in data base. db2 connect to DB STATUS=$(db2 "SELECT STATUS FROM XYZ ) echo $STATUS Initially the status value will be '4' or 'NOT YET RUN'. The Shell script has to run until the status value is updated... (7 Replies)
Discussion started by: sumanmca2006
7 Replies

4. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

5. 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

6. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

7. UNIX for Dummies Questions & Answers

opposite return status in c shell

there is something wrong with my system. when I do this: diff file1 file1 && echo 1 the output is 1. but diff file1 file2 >/dev/null && echo 1 output nothing while diff file1 file2 >/dev/null || echo 1 shows 1. the same with "grep" return status. they are both GNU utilities.... (5 Replies)
Discussion started by: phil518
5 Replies

8. Shell Programming and Scripting

trigger a script based on the run status of another scipt

Im a newbee.. I have a script which runs few times daily. I want to write another script which should pick up the latest log generated from the last run of the first job and trigger a thrid script if the first script runs successfuly. Please help... Cheers (1 Reply)
Discussion started by: Athena
1 Replies

9. Shell Programming and Scripting

Return status...

Hello there! Here is my problem. I hope I can get some help about it. I need to know how can I get the return code of an application in the Unix shell script. The script is like below: PREVIOUS STATEMENT & VARIABLES sqlplus scott/tiger @$sqldir/$sqlscript NEXT STATEMENT (Like... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question