The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 07:44 AM
sendmail return code trichyselva Shell Programming and Scripting 0 04-02-2008 08:20 AM
asking about return code naamas03 Shell Programming and Scripting 3 08-28-2007 05:53 AM
Return Code of tar in AIX dupeng AIX 3 02-23-2004 12:05 AM
return code from oracle lesstjm Shell Programming and Scripting 3 01-29-2002 03:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-06-2006
u263066 u263066 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 66
Incorporte Return Code

I am writing a script to call sql script and thus caputure few return type.
here is the script:
Code:
   
echo "Checking for Loader Status " >>  $REPFILE
    if test $? = 0
    then
        echo "Successful termination of SQL*Loader "$LOADER1  >> $REPFILE
        grep "successfully loaded." $LOGDIR/$LOADER1.log >> $REPFILE
    else 
	echo "Loader has some problems " >>  $REPFILE       
	PROBLEMS=1
    fi   
if test $PROBLEMS = 1
then
    echo "\nUnsuccessful termination of" $SCRIPT >> $REPFILE
    exit 1
else
    echo "\n----------------------------------" >> $REPFILE
    echo "Successful termination of" $SCRIPT >> $REPFILE
    echo "----------------------------------" >> $REPFILE
fi
exit 0
now this works fine for Return Code =0
but I need to create few more like
HTML Code:
0 echo "SQL*Loader execution successful" ;;
1 echo "SQL*Loader execution exited with failure, see logfile" ;;
2 echo "SQL*Loader execution exited with warning, see logfile" ;;
3 echo "SQL*Loader execution encountered a fatal error" ;;
* echo "unknown return code";;
Hello I have to incorporte other consitions like
1,,2,3, *
but unable to proceed.tried for 1 also but fails .

The code works fine with 0
Can anyone provide input how to create and construct other conditions.
  #2 (permalink)  
Old 09-06-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
write a function

Write a function like check_status and pass the return code as a variable. Inside the function, use case syntax
Code:
function check_status
{
ret_code=$1
case $ret_code in 
0) ....
    break;;
1) ....;
     break;;
*) --default action here;
esac;
}
  #3 (permalink)  
Old 09-06-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by u263066
echo "Checking for Loader Status " >> $REPFILE
if test $? = 0
then
The problem is that "$?" contains the exit code of the previous "echo" which is always "0".

For instance, if you want the exit status of "sql.sh", then you could do:
Code:
sql.sh
SQL_STATUS=$?
echo "Checking for Loader Status " >>  $REPFILE
    if test $SQL_STATUS = 0
[...]
Regards.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0