![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MMU exception | Puntino | Linux | 2 | 05-07-2008 09:35 AM |
| Help with RPC Exception | ejbrever | HP-UX | 2 | 08-24-2006 11:08 AM |
| RPC Exception - Help | ejbrever | UNIX for Advanced & Expert Users | 0 | 08-21-2006 09:56 AM |
| Linux g++ 2.95.3 exception handling | earl | High Level Programming | 0 | 08-16-2005 10:46 AM |
| exception handling | RichardS | UNIX for Advanced & Expert Users | 1 | 06-16-2004 02:29 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Try to use the 'set -e' command.
Extract from man page : Quote:
Code:
set -e export id=root export db=testcsv export db_add=localhost mysql -h$db_add -u$id -D$db <loadA.sql |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|
#5
|
|||
|
|||
|
Thanks Man - Brilliant
|
|||
| Google The UNIX and Linux Forums |