Oracle Alert log script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Oracle Alert log script
# 1  
Old 05-18-2012
Oracle Alert log script

Hi,
I'm trying to write a shell script on HP-UX to search through Oracle alert logs for errors which always start with ORA-. If it does find an error I'd like it to print the date line (which precedes the error by a line or two normally) as well as the error line. So in the example below I'd like it to print the two bolded lines.

Can anyone give me a hint on this, maybe simply using grep or awk?

Code:
Fri May 18 12:25:22 2012
LNS: Standby redo logfile selected for thread 1 sequence 315357 for destination LOG_ARCHIVE_DEST_6
Fri May 18 12:25:26 2012
ARC3: Standby redo logfile selected for thread 1 sequence 315356 for destination LOG_ARCHIVE_DEST_2
Fri May 18 12:25:28 2012
ARC1: Standby redo logfile selected for thread 1 sequence 315356 for destination LOG_ARCHIVE_DEST_4
Fri May 18 12:25:31 2012
ARC0: Standby redo logfile selected for thread 1 sequence 315356 for destination LOG_ARCHIVE_DEST_6
Fri May 18 12:25:37 2012
Errors in file /u02/oracle/admin/prod/bdump/prod1/prod1_arc0_4457042.trc:
ORA-16401: archivelog rejected by RFS
Fri May 18 12:31:36 2012
Thread 1 advanced to log sequence 315358
  Current log# 23 seq# 315358 mem# 0: /dev/rdprod_0000501
  Current log# 23 seq# 315358 mem# 1: /dev/rdprod_0000502
Fri May 18 12:31:37 2012
LNS: Standby redo logfile selected for thread 1 sequence 315358 for destination LOG_ARCHIVE_DEST_2
Fri May 18 12:31:38 2012
LNS: Standby redo logfile selected for thread 1 sequence 315358 for destination LOG_ARCHIVE_DEST_6
Fri May 18 12:31:47 2012

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 05-18-2012 at 04:16 PM..
# 2  
Old 05-18-2012
Code:
$ cat oralog.awk

# Recall N lines ago up to 9 lines
function last(N)
{
        if(N>L) return("");
        return(LINE[(L-N)%10]);
}

{ LINE[(++L)%10]=$0 } # Remember line for later

# Lines beginning with ORA
/^ORA-/ {
        # Hunt backwards for a line ending in HH:MM:SS YYYY
        for(N=1; N<=9; N++)
        if(last(N) ~ /[0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/)
                        break;

        print last(N); # Print the timestamp
        print; # Print the error
}

$ awk -f oralog.awk data

Fri May 18 12:25:37 2012
ORA-16401: archivelog rejected by RFS

$

If awk doesn't work, try nawk or gawk.
These 3 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help searching for dates - Oracle ALERT log

Hi, I am searching for some specific string in an Oracle DB alert log and then possibly print the latest date string that I can find that the error happen. I can't work out how to search for date strings more so searching in some specific direction, i.e backward or forward. At the moment,... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. SuSE

Alert for Audit log

Dear users, I have SLES 11 and SLES 10 servers. I'd like to receive an alert when audit log files reach certain percentage of full. 1. Is '/etc/audit/auditd.conf' the right file to modify? 2. I'd like to receive email alert. Can I specify my email in this parameter 'action_mail_acct... (1 Reply)
Discussion started by: JDBA
1 Replies

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

4. Shell Programming and Scripting

Check log file size every 10 minute. Alert if log not update

How to check log size every 10min. by script (can use crontab) if log size not change with alert "Log not update" Base run on SunOS 5.8 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise logFiles="log1.log log2.log" logLocation="/usr/home/test/log/" Out put. Tue Jan 31... (3 Replies)
Discussion started by: ooilinlove
3 Replies

5. Shell Programming and Scripting

Shell script to capture ORA errors from Alert Log

Hi, as the title says, I am after a simple script, which will open the Alert log from an 11.2.0.1 Linux environment and mail the error message and description to a recipient email address. I can then schedule this job via cron and let it run every 15 minutes. I have searched online... (16 Replies)
Discussion started by: jnrpeardba
16 Replies

6. Shell Programming and Scripting

help with script Alert log not update every time.

:p Hello :) This is my script . This check log file size every 1 minute. Credit code https://www.unix.com/shell-programming-scripting/151723-help-writing-script-check-log-not-update.html #! /bin/bash logFiles="log1.log log2.log" logLocation="/usr/home/test/log/" sleepTime=60 ... (8 Replies)
Discussion started by: ooilinlove
8 Replies

7. Shell Programming and Scripting

shell script not getting current error messages with time from alert.log

Hi All, I need to get current error messages with time from alert.log.Below is my shell script but it's not working to meet this objective. could anyone pls share on the above issue for resolution: #################################################################### ## ckalertlog.sh ##... (2 Replies)
Discussion started by: a1_win
2 Replies

8. Shell Programming and Scripting

alert_oss.log oracle log file in hp-unix

Hi I have go this alert_oss.log that is basically capturing all the oracle errorlogs.Now the problem is that it is one huge file and to see log of some particular date i tried cat alert_oss.log | grep 'Mar 25 10:44:45 2007' > alert_25.txt is not giving me the required output. pls suggest ... (3 Replies)
Discussion started by: Assassin
3 Replies
Login or Register to Ask a Question