UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 2005, 01:54 PM
jabs jabs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 19 jabs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 26 sec
Reputation Power: 0
Parsing Oracle errors in script

Hi everyone.

I have a very simple script that uses oracle's 'imp' command to import data into a database. Once the process is finished, it emails me using mailx. Occasionally, it fails. I would like to be able to know when it fails and send a different email in case of failure. I know how to capture Oracle failures in PL/SQL, but not in unix. Can anyone help?

Here is a snippet of code: (As i mentioned, it's very simple)

**************

imp username/pass@db buffer=......TABLES=TABLENAME


mailx -s "table imp" Joe <<+++
table imported.
+++

***************

Thanks for your help!

Reply With Quote
  #2  
Old July 27th, 2005, 02:18 PM
stdunbar stdunbar is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 1,730 stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 23 h 21 m 6 sec
Reputation Power: 375
Send a message via ICQ to stdunbar Send a message via Yahoo to stdunbar
At a guess the command will exit with a different value if it fails. In traditional Unix programs a zero exit value means that everything went ok. I find Oracle's docs almost impossible to navigate so a quick look on OTN didn't tell me what the exit values for imp are when it fails but you would usually want to do something like:

Code:
RETVAL=0
imp username/pass@db buffer=......TABLES=TABLENAME
RETVAL=$?
if [ $RETVAL = 0 ] ; then
    mailx -s "table imp" Joe <<+++
    table imported.
    +++ 
elif [ $RETVAL = 1 ] ; then
    mailx -s "table imp" Bob<<+++
    table import failed.
    +++ 
fi


Now, having written this, please understand that I'm not the worlds expert on shell scripts but something like this should be close.

Last edited by stdunbar : July 27th, 2005 at 02:24 PM. Reason: Fixed some wierdness on the OTN link

Reply With Quote
  #3  
Old July 27th, 2005, 02:45 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 20 m 41 sec
Reputation Power: 48
imp does in fact return ZERO on sucess and non-zero on failure (almost always 1).
Code:

if [ $RETVAL -eq 0 ] ; then
    mailx -s "table imp" Joe <<+++
    table imported.
    +++
else

    mailx -s "table imp" Bob<<+++
    table import failed.
    +++
fi

Reply With Quote
  #4  
Old July 27th, 2005, 03:28 PM
jabs jabs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 19 jabs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 26 sec
Reputation Power: 0
Quote:
Originally Posted by stdunbar
At a guess the command will exit with a different value if it fails. In traditional Unix programs a zero exit value means that everything went ok. I find Oracle's docs almost impossible to navigate so a quick look on OTN didn't tell me what the exit values for imp are when it fails but you would usually want to do something like:

Code:
RETVAL=0
imp username/pass@db buffer=......TABLES=TABLENAME
RETVAL=$?
if [ $RETVAL = 0 ] ; then
    mailx -s "table imp" Joe <<+++
    table imported.
    +++ 
elif [ $RETVAL = 1 ] ; then
    mailx -s "table imp" Bob<<+++
    table import failed.
    +++ 
fi


Now, having written this, please understand that I'm not the worlds expert on shell scripts but something like this should be close.


Ok - I see what you're doing - if the error code is something different, I'll try to find it. Thanks a lot for your help!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Parsing Oracle errors in script


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT