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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Exit Codes cmschube Shell Programming and Scripting 1 04-04-2008 08:34 AM
Exit codes in SFTP vikramsnest Shell Programming and Scripting 1 08-15-2007 11:08 PM
exit codes from rexec? diego_sapphire UNIX for Dummies Questions & Answers 3 08-16-2005 02:36 PM
Where can I find a list of exit codes? (Exit code 64) jkuchar747 UNIX for Dummies Questions & Answers 3 12-07-2004 02:08 PM
exit codes donna carter High Level Programming 3 05-31-2001 06:35 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-16-2006
Registered User
 

Join Date: Feb 2006
Posts: 1
Stumble this Post!
Catching all Exit Codes

I have a Unix Script that has several exit in the middle. each returning seperate
exit codes.

I have to catch all the exit's and perform an operation say "Mail the status code" before the actual code completes.

How can i do this in KSH ?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-16-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,658
Stumble this Post!
Introduce a function to catch all the exit codes.

Something like

Code:
 
EXIT_CODE=""

function assembleExitCode
{
EXIT_CODE="${EXIT_CODE} $@"
}
At every place where you are looking for an exit code, invoke the function as
Code:
assembleExitCode $?
At the end of the code,

Code:
if [[ x"$EXIT_CODE" != x ]] ; then
echo "Mail status"
fi ;
Reply With Quote
  #3 (permalink)  
Old 02-16-2006
Registered User
 

Join Date: Feb 2006
Posts: 34
Stumble this Post!
Try this

case $? in
1) echo "Exit message1";;
2) echo "Exit message2";;
.
.
.
esac
Reply With Quote
  #4 (permalink)  
Old 02-16-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
Stumble this Post!
trap "command" EXIT


man ksh trap
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0