Exception-handling in Shell programs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exception-handling in Shell programs
# 1  
Old 08-25-2008
Question 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 the deepest-nested command causing the failure and preferably a call trace.

To do this, trap could be used I was told but I am not sure trap's functionality is enough for my need. What do you think is the best way here?

It's a constraint at this place that I use only shell and not a full-blown programming language. Any help from you guys is greatly appreciated.

Best Regards,
Chaitanya
# 2  
Old 08-25-2008
Will each of the scripts that you invoke be doing detailed error checking? If the last script executed runs a command that fails, it could print the error and return a failure code.

If you write each script to do that, your trace takes care of itself, without any additional effort required (other than what you need to put in for the scripts themselves).
# 3  
Old 08-25-2008
Question

Hi blowtorch,

No, I wasn't planning on putting detailed error checks in each of the scripts...they are too long (5000+ lines) and doing that that would take me forever. I am looking more from a less-involved solution. Do you think it's possible actually? Something like - (I am vague I know but it's the best I can do!) -

1. Start a guarded environment at the beginning of each script (guarded as in - each command is executed and if it succeeds, alright; otherwise, break the whole program right there).

2. Execute each command in the script (without explicitly coding for error-checking, i.e.)

3. Run an event like trap in case of failure, and fire an email.

What do you say...?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

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

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

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

5. Shell Programming and Scripting

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 ... (5 Replies)
Discussion started by: bertpereira
5 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

Gen. Question - Script calls multiple programs - Return Code Handling?

General Question: If a script calls multiple external programs (external to the script, but still on unix), where do the return codes go? Let's say one of external programs fails, does the entire script fail and send a non-zero return code to the job scheduling software, or is the return code sent... (1 Reply)
Discussion started by: jnanasakti
1 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