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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script file handling nathgopi214 Shell Programming and Scripting 1 03-26-2008 01:04 PM
How to find out Errors in FTP Scripts sourabhshakya Shell Programming and Scripting 1 06-13-2006 07:40 AM
signal handling in shell script Raom UNIX for Advanced & Expert Users 4 12-08-2005 06:55 AM
Error Handling in Korn Shell scripts bhgopi UNIX for Advanced & Expert Users 4 09-06-2005 06:44 PM
Null handling in scripts mohanprabu Shell Programming and Scripting 3 01-20-2005 04: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 12-24-2006
sarsani sarsani is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
Handling Errors in Shell Scripts

I have a shell script, which calls a load script to load a database. How can i handle errors in Unix(similar to 'error level' in Batch scripts)? I am trying to use 'mailx' to send a Success/failure message based on the error level returned by the load script.

I have already used an error log file to find out success or failure of the load script, but sometimes there will be some errors even though it does not create an error log file, so its not 100% accurate.

Thanks
  #2 (permalink)  
Old 12-24-2006
kbrede kbrede is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 21
In bash the return code of a prog is in $?. Usually exit status 0 = success and 1 = failure.

If we look in the manpage for grep we find:

Normally, exit status is 0 if selected lines are found and 1 otherwise. But the exit status is 2 if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found.


Based on that, an example of usage:

---------------------------
#!/bin/bash

/bin/grep search_string file

if [ $? -eq 1 ];then
echo "String not found."
fi
---------------------------

Hope that gets you on your way.
Kent
  #3 (permalink)  
Old 12-24-2006
sarsani sarsani is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
That worked thanks.
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 11:11 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