Visit Our UNIX and Linux User Community


Shell script to capture ORA errors from Alert Log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to capture ORA errors from Alert Log
# 8  
Old 06-08-2011
save the file with .sh extension and assign the execute permission and run the shell script
# 9  
Old 06-08-2011
Hi,

that's perfect, thanks.

However is it possible to only capture that particular day's errors. So for example this will be run on a daily basis, say 3am and I would like the ORA error message for only the previous day. Is this possible?

Many thanks for your assistance
# 10  
Old 06-08-2011
Yes, this is for Linux (or any other system that has the GNU date installed):

Code:
#!/bin/bash


ORACLE_HOME=<your_oracle_home>
ORACLE_SID=<your_oracle_sid>
ORAENV_ASK=NO
export ORACLE_HOME ORACLE_SID ORAENV_ASK

_mailto=<your_email_address>
_mail_subject="Alert for $ORACLE_SID on $HOSTNAME"
_today=$(
  date '+%Y-%m-%d 00:00:00'
  )
_yesterday=$(
  date -d yesterday +'%Y-%m-%d 00:00:00'
  )  

_my_result=$(
  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP between '$_yesterday' and '$_today'\\\"
   "
  )

case $_my_result in 
  ( *ORA-* ) mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"  
esac

# 11  
Old 06-08-2011
Thanks for that - now when I execute the script nothing happens.
I would like to capture the script to see what happens but if I execute file.sh > file.log the log file is empty

This is the script you sent me with the 3 necessary changes in bold. Any suggestions?


Code:
[oracle@ukedxdtmtdbs01a scripts]$ more test.sh
#!/bin/bash


ORACLE_HOME=ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_SID=DCTMTEST1
ORAENV_ASK=NO
export ORACLE_HOME ORACLE_SID ORAENV_ASK

_mailto=name@company.com
_mail_subject="Alert for $ORACLE_SID on $HOSTNAME"
_today=$(
  date '+%Y-%m-%d 00:00:00'
  )
_yesterday=$(
  date -d yesterday +'%Y-%m-%d 00:00:00'
  )

_my_result=$(
  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP between '$_yesterday' and '$_today'\\\"
   "
  )

case $_my_result in
  ( *ORA-* ) mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"
esac
[oracle@ukedxdtmtdbs01a scripts]$


Last edited by radoulov; 06-08-2011 at 09:12 AM.. Reason: Code tags.
# 12  
Old 06-08-2011
Quote:
Originally Posted by jnrpeardba
Thanks for that - now when I execute the script nothing happens.
I would like to capture the script to see what happens but if I execute file.sh > file.log the log file is empty
[...]
This is correct. If you want to see what happens just run the script with -xv:

Code:
bash -xv <script_file>

If there are no errors for the specified period (yesterday), nothing happens,
otherwise you'll receive the mail with the errors.
# 13  
Old 06-08-2011
Thanks very much - It worked as there were no errors yesterday, but I would have expected for it to mail me - and say that - or does it only mail on error, i.e if it finds something? output from running with -xv



Code:
[oracle@ukedxdtmtdbs01a scripts]$ bash -xv test.sh
#!/bin/bash


ORACLE_HOME=ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
+ ORACLE_HOME=ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_SID=DCTMTEST1
+ ORACLE_SID=DCTMTEST1
ORAENV_ASK=NO
+ ORAENV_ASK=NO
export ORACLE_HOME ORACLE_SID ORAENV_ASK
+ export ORACLE_HOME ORACLE_SID ORAENV_ASK

_mailto=name@company.com
+ _mailto=name@company.com
_mail_subject="Alert for $ORACLE_SID on $HOSTNAME"
+ _mail_subject='Alert for DCTMTEST1 on ukedxdtmtdbs01a.pearson.com'
_today=$(
  date '+%Y-%m-%d 00:00:00'
  )

  date '+%Y-%m-%d 00:00:00'
++ date '+%Y-%m-%d 00:00:00'

+ _today='2011-06-08 00:00:00'
_yesterday=$(
  date -d yesterday +'%Y-%m-%d 00:00:00'
  )

  date -d yesterday +'%Y-%m-%d 00:00:00'
++ date -d yesterday '+%Y-%m-%d 00:00:00'

+ _yesterday='2011-06-07 00:00:00'

_my_result=$(
  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP between '$_yesterday' and '$_today'\\\"
   "
  )

  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP between '$_yesterday' and '$_today'\\\"
   "
++ adrci 'exec=
    set home DCTMTEST1;
    show alert -term -P \"MESSAGE_TEXT like '\''%ORA%'\'' and ORIGINATING_TIMESTAMP between '\''2011-06-07 00:00:00'\'' and '\''2011-06-08 00:00:00'\''\"
   '

+ _my_result='DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [DCTMTEST1]

DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA'

case $_my_result in
  ( *ORA-* ) mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"
esac
+ case $_my_result in


Last edited by radoulov; 06-08-2011 at 09:22 AM.. Reason: Code tags.
# 14  
Old 06-08-2011
Modified the script as per your requirement (mail in any case).
There was an error in the previous version of the script that I corrected: oraenv wasn't sourced. You may need to adjust the path to oraenv.

Code:
#!/bin/bash


ORACLE_HOME=<your_oracle_home>
ORACLE_SID=<your_oracle_sid>
ORAENV_ASK=NO
export ORACLE_HOME ORACLE_SID ORAENV_ASK

# you may need to adjust the path to oraenv
. "$ORACLE_HOME"/bin/oraenv

_mailto=<your_email_address>
_mail_subject_ok="No ORA- for $ORACLE_SID on $HOSTNAME"
_mail_subject_ko="ORA- for $ORACLE_SID on $HOSTNAME"

_today=$(
  date '+%Y-%m-%d 00:00:00'
  )
_yesterday=$(
  date -d yesterday +'%Y-%m-%d 00:00:00'
  )  

_my_result=$(
  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP between '$_yesterday' and '$_today'\\\"
   "
  )

[[ $_my_result == *ORA-* ]] && 
  _mail_subject=$_mail_subject_ko ||
    _mail_subject=$_mail_subject_ok

mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"


Please post the output of bash -xv <script_name> so I can verify the correct execution.

Previous Thread | Next Thread
Test Your Knowledge in Computers #340
Difficulty: Easy
Apache2 is a web server developed by Apple Computer.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check for “errors” or “ORA-”

I want to check for "errors" or "ORA-" in Y.if there is an error then exit Y=`sqlplus -s user/passwd<< EOF exec test_Proc; exit; EOF` if ; then exit 1 fi but this doesnt work (6 Replies)
Discussion started by: haadiya
6 Replies

2. Shell Programming and Scripting

Shell script to capture Current day ORA errors from Alert Log

Please provide Shell script to capture ORA errors from Alert Log for a given date or Current date. -Veera (1 Reply)
Discussion started by: Veera_V
1 Replies

3. Shell Programming and Scripting

Extracting Sysdate-1 ORA Errors - Can you help me in this UNIX Script?

Hi Guys, I wanted to create an Unix Shell Script that should fetch a particular string from a text file on a particular date. We all know Oracle generates alert logs for each and every day for every actions in the database. I have an alert log file now where it contains for about a months... (4 Replies)
Discussion started by: raja_dba
4 Replies

4. Shell Programming and Scripting

How to turn off ora errors in shell script?

I have a shell script which select total count from a table and use its value in a if condition like below connect_string="username/password@tnsname" tot=`sqlplus -s $connect_string << EOF set echo off set feedback off set head off select count(*) from test_table; EOF ` if then echo... (2 Replies)
Discussion started by: vel4ever
2 Replies

5. Shell Programming and Scripting

Capture makefile errors in shell script

Hi, I have a bash script which calls a few "make". I would like to know whether the makefile failed with any errors. How do I do that in the script? Thanks, S (2 Replies)
Discussion started by: suryaemlinux
2 Replies

6. UNIX for Advanced & Expert Users

grep all ORA errors except one ORA error

Hi - I am trying to grep all "ORA" errors in a log files.I have to grep all ORA errors except one error for example ORA-01653.How can exclude that error in "grep" command? In following "grep" command I want to exclude "ORA-01653" error grep -i ORA alert.log >>/tmp/ora_errors.txt ... (7 Replies)
Discussion started by: Mansoor8810
7 Replies

7. Shell Programming and Scripting

Script to capture date/time in seconds in PERL... Cant understand errors

I'm Using this script to find the time of a file. I'm very much new to PERL and found this script posted by some one on this forum. It runs perfectly fine, just that it gives me following errors with the accurate output as well. I jus want the output to be stored in another file so that i can... (0 Replies)
Discussion started by: bankimmehta
0 Replies

8. Shell Programming and Scripting

Need to capture the service name from tnsnames.ora and create connect string

ghkjkjoj (4 Replies)
Discussion started by: chetankelvin
4 Replies

9. Shell Programming and Scripting

Script to capture errors

Hello; I'm trying to write a script to capture any hardware error from logs/syslog on my SUSE 10 servers so i can be notified if we have any hardware issues such a bad fan or battery, etc.. Thanks in advance for any help (2 Replies)
Discussion started by: Katkota
2 Replies

10. Shell Programming and Scripting

How to get ORA errors in alertlog file using shell script.

Hi, Can anyone tell me how to get all ORA errors between two particular times in an alertlog file using shell script. Thanks (3 Replies)
Discussion started by: suman_dba1
3 Replies

Featured Tech Videos