![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|