Exception Handling


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exception Handling
# 1  
Old 05-24-2007
Network Exception Handling

Hi,

I have written a script to load csv files into a mysql database, however, i would like for the shell script to exit in the event of an error (missing file, load error etc.) - currently if an error is encountered the next statement is processed - This is how i am loading the csv scripts

export id=root
export db=testcsv
export db_add=localhost

mysql -h$db_add -u$id -D$db <loadA.sql

Thanks in advance

Bert
# 2  
Old 05-24-2007
Try to use the 'set -e' command.
Extract from man page :

Quote:
-e If a command has a non-zero exit status, execute the ERR
trap, if set, and exit. This mode is disabled while reading profiles.
Code:
set -e
export id=root
export db=testcsv
export db_add=localhost

mysql -h$db_add -u$id -D$db <loadA.sql

Jean-Pierre.
# 3  
Old 05-24-2007
Thanks!!!

Awesome!!!! - Is there a way i can GOTO a certain block if such an error is trapped?? - for instance once the error is encountered GOTO cleanup-script block??
# 4  
Old 05-24-2007
You can use the trap command :

Code:
cleanup_script()
{
   echo "Cleaning ..."
}
trap 'cleanup_script' ERR
set -e

export id=root
export db=testcsv
export db_add=localhost

mysql -h$db_add -u$id -D$db <loadA.sql

Jean-Pierre.
# 5  
Old 05-24-2007
MySQL Thanks!!!

Thanks Man - Brilliant Smilie
# 6  
Old 01-14-2009
Hi Aigles,

I also have similar requirement as in this chain, i have written the shell script to execute a COBOL program which loads the data into Peoplesoft tables. If for some reason if the data load fails which means if the COBOL program fails i want the script to be errored and should be proceed with the rest of the process. Can i get some sample script of this type or any help is highly appreciated.

Kannan
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

2. Solaris

solaris 7 exception

Hi all, An application works well under 2.6 but under 7 it gives TEXT_IO exceptions. (Is_Open, Check_Is_Open, Get_Line procedures). Any idea? Regards (3 Replies)
Discussion started by: endoavour
3 Replies

3. Programming

Exception Handling C++

Hello All, I have a question ....which I am totally confused about! If I have a fxn foo in a program which returns a logical value. But it has a posssiblity to throw some exception. Now my exception handler returns a value as a string stating why the exception occured. But my... (1 Reply)
Discussion started by: mind@work
1 Replies

4. Shell Programming and Scripting

Exception handling

Sometimes when I try to use curl to upload to an ftp server, I get the message: $curl -T file.wmv ftp.eu.filesonic.com --user user:password curl: (8) Got a 421 ftp-server response when 220 was expected How do I get the script to try again if I get the message curl: (8)? (2 Replies)
Discussion started by: locoroco
2 Replies

5. Programming

Advanced Exception Handling in C++

Hi Friend, Could you please provide me with some tutorial for Advanced Exception handling in C++, mainly set_terminate() and set_unexpected() functions? Please find the details below: OS: Unix Compiler: gcc. Thanks. :) Awesome001 (0 Replies)
Discussion started by: awesome001
0 Replies

6. Linux

Handling "command not found" exception

hello friends, I am given a project to handle the command not found exception.I am using RED HAT 9. Generally, when we press a wrong command in the terminal: example :- " $cet " in place of " $cat ". Then we get this exception. But I need to give the output as the combinations that are possible... (5 Replies)
Discussion started by: nsharath
5 Replies

7. Shell Programming and Scripting

Exception-handling in Shell programs

Hi all, I am writing a set of scripts and some of these are nested within others. I want to be able to execute a single high-level script at the command-line, which in turn may invoke other scripts as required, and when a failure occurs in any of the nested scripts, I want to be able to track... (2 Replies)
Discussion started by: chaitu_inmage
2 Replies

8. Programming

Linux g++ 2.95.3 exception handling

Anybody happen to be familiar with any deficiencies with g++ 2.95.3 regarding exception handling, specifically in multi-threaded / multi-module (shared library) based applications? I'm seeing behavior where thrown exceptions are not caught, but basically ignored causing the application to... (0 Replies)
Discussion started by: earl
0 Replies

9. UNIX for Advanced & Expert Users

exception handling

Does exception handling exist in any UNIX enviornment? I develop on Windows MSVC++ land and need to port to UNIX. (1 Reply)
Discussion started by: RichardS
1 Replies
Login or Register to Ask a Question