The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to get the exit status yhacks Shell Programming and Scripting 1 05-19-2008 08:06 AM
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-09-2006 01:08 AM
Checking the exit status of ftp psingh UNIX for Advanced & Expert Users 1 06-04-2002 10:51 PM
tar exit status thorndike UNIX for Dummies Questions & Answers 3 01-22-2002 04:39 PM
ftp exit status. oracle8 UNIX for Advanced & Expert Users 1 10-21-2001 11:34 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 10-18-2005
PrimeRibAndADew PrimeRibAndADew is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
Checking Exit Status

I hope one of you smart people out there can help me with what seems like a real simple questing but I can't quite figure out.

In a script I am doing a cmp on two files. I am trying to check the exit status with an if statement but can't seem to figure out the syntax. If the exit status is 1 I want to do something else something else. I am using Solaris 8 and my shell is ksh.
  #2 (permalink)  
Old 10-18-2005
GNMIKE GNMIKE is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 45
Hi,
As far as I know any unix command returns a return code. Depending on the shell you use the check may slightly differ.

If you are using ksh - The following should work

....your command here....
rtrncd=$?
if [ $rtrncd -ne 0 ]
then
echo problems # problem happened
exit $rtrncd # exit with the same bad return code
fi
# no problems happened - Continue with your scrip
....possibly more code here....

Hope this helps
  #3 (permalink)  
Old 10-19-2005
PrimeRibAndADew PrimeRibAndADew is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
Well I do not get the errors I was getting. Here is what I have in the script followed by the error message.

#!/usr/bin/ksh

cmp file1 file2

rtrncd=$?

if [$rtrncd -ne 0 ] then
cat error-message-file | mailx -s "Error `date`" email address
exit $rtrncd
fi


The error I get is
check_rep2.sh[7]: syntax error at line 11 : 'fi' unexpected


Mike
  #4 (permalink)  
Old 10-19-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
You need spaces around [ and ] and also "then" is a separate command...you must put it on a new line or use a semicolon.

if [ $rtrncd -ne 0 ] ; then
  #5 (permalink)  
Old 10-19-2005
PrimeRibAndADew PrimeRibAndADew is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
That's it. Thanks for the help.

Mike
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 08:30 PM.


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