|
|
|
|
Re: Shell Script to extract "Particular Content" from a Text File. [message #582075 is a reply to message #582073] |
Fri, 12 April 2013 22:59 |
|
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
A simple awk could do. Something like this.
This will get April 11 entries. Hopefully your logfile does not have entries more than a year
You can make it any fancier.
oracle@ark#awk '/Apr 11/,/Apr 12/' alert_freeze.log | sed '$d'
Thu Apr 11 01:34:25 2013
Thread 1 advanced to log sequence 260 (LGWR switch)
Current log# 2 seq# 260 mem# 0: +FREEZE/redo03.log
Current log# 2 seq# 260 mem# 1: +FREEZE/redo04.log
Thu Apr 11 02:00:00 2013
Closing scheduler window
Closing Resource Manager plan via scheduler window
Clearing Resource Manager plan via parameter
Thu Apr 11 19:15:03 2013
DM00 started with pid=41, OS id=8489, job DBADMIN.SYS_EXPORT_FULL_01
Thu Apr 11 19:15:06 2013
DW00 started with pid=35, OS id=8493, wid=1, job DBADMIN.SYS_EXPORT_FULL_01
Thu Apr 11 19:21:16 2013
Thread 1 cannot allocate new log, sequence 261
Private strand flush not complete
Current log# 2 seq# 260 mem# 0: +FREEZE/redo03.log
Current log# 2 seq# 260 mem# 1: +FREEZE/redo04.log
Thread 1 advanced to log sequence 261 (LGWR switch)
Current log# 1 seq# 261 mem# 0: +FREEZE/redo01.log
Current log# 1 seq# 261 mem# 1: +FREEZE/redo02.log
Thu Apr 11 19:40:28 2013
Thread 1 cannot allocate new log, sequence 262
Private strand flush not complete
Current log# 1 seq# 261 mem# 0: +FREEZE/redo01.log
Current log# 1 seq# 261 mem# 1: +FREEZE/redo02.log
Thread 1 advanced to log sequence 262 (LGWR switch)
Current log# 2 seq# 262 mem# 0: +FREEZE/redo03.log
Current log# 2 seq# 262 mem# 1: +FREEZE/redo04.log
Thu Apr 11 22:00:00 2013
Setting Resource Manager plan SCHEDULER[0x40BC3]:DEFAULT_MAINTENANCE_PLAN via scheduler window
Setting Resource Manager plan DEFAULT_MAINTENANCE_PLAN via parameter
Thu Apr 11 22:00:00 2013
Starting background process VKRM
Thu Apr 11 22:00:00 2013
VKRM started with pid=28, OS id=15233
Thu Apr 11 22:00:04 2013
Begin automatic SQL Tuning Advisor run for special tuning task "SYS_AUTO_SQL_TUNING_TASK"
Thu Apr 11 22:00:23 2013
End automatic SQL Tuning Advisor run for special tuning task "SYS_AUTO_SQL_TUNING_TASK"
And just redirect the output.
oracle@ark#awk '/Apr 11/,/Apr 12/' alert_freeze.log | sed '$d' > thisLog
oracle@ark#ls -lart thisLog
-rw-r--r-- 1 oracle dba 1805 Apr 13 00:02 thisLog
[Updated on: Fri, 12 April 2013 23:03] Report message to a moderator
|
|
|
|
Re: Shell Script to extract "Particular Content" from a Text File. [message #582080 is a reply to message #582073] |
Sat, 13 April 2013 00:48 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:I am using 10G Mahesh.
You can use an external table on the alert.log file then you have power of SQL to do what you want:
-- Retrieve alert.log file name and directory
define bdump = ' '
define alert = ' '
col value heading "Background dump dest" new_value bdump
col log heading "Alert log" new_value alert
select value, 'alert_'||instance_name||'.log' log -- Unix
from v$instance, v$parameter
where name='background_dump_dest'
/
-- Create Oracle directory
create or replace directory aol_bdump as '&&bdump'
/
-- Create external table for the alert.log file
create table alert_log_ext (line varchar2(2000))
organization external (
type oracle_loader
default directory aol_bdump
access parameters (
records delimited by newline
nobadfile
nologfile
nodiscardfile
fields
missing field values are null
(line position (1:2000))
)
location ('&&alert')
)
reject limit unlimited
/
Regards
Michel
[Updated on: Sat, 13 April 2013 00:48] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Re: Shell Script to extract "Particular Content" from a Text File. [message #582213 is a reply to message #582097] |
Mon, 15 April 2013 22:56 |
|
raja_dba
Messages: 33 Registered: November 2012 Location: India
|
Member |
|
|
Mahesh Rajendran wrote on Sat, 13 April 2013 16:29No need to EOF as you are not using a "here" document in this case.
Keep it simple to start with.
oracle@ark#cat someScript
awk "/$1 $2/,/$3 $4/" alert_freeze.log | sed '$d' > thisLog
oracle@ark#./someScript Apr 11 Apr 12
Mahesh,
I am sorry for the delayed response.
I am still finding difficult to bring the results.
I was trying this,
===================================
SCRIPT
cd /back/alert/log
a=`date '+%b %d' -d "yesterday"`
b=`date '+%b %d'`
c="$a $b"
echo "$c"
awk "/$1 $2/,/$3 $4/" alert_dbname.log | sed '$d'
exit
=================================================
echo "$c" would output yesterday's date and today's date in the format
Apr 15 Apr 16
And from here I want to substitute the Apr 15 Apr 16 in awk as
[[[ awk '/Apr 15/,/Apr 16/' alert_dbname.log | sed '$d' | grep ORA ]]]]
And for this substitution I have written in the script
awk "/$1 $2/,/$3 $4/" alert_dbname.log | sed '$d'
But this doesn't bring me the required output.
The ultimate aim of this script is to find Day-1 ORA errors and I want this to be automated by an Unix Shell Script.
Could you please help me out again?
Thanks,
Raja
[Updated on: Mon, 15 April 2013 23:56] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: Shell Script to extract "Particular Content" from a Text File. [message #582284 is a reply to message #582283] |
Tue, 16 April 2013 09:55 |
|
raja_dba
Messages: 33 Registered: November 2012 Location: India
|
Member |
|
|
Mahesh,
All the inputs you have provided here are much useful and it is just that I was not knowing certain stuffs to develop the script for my required result.
However I tried this concept ( == > Connection ) and it seem to work but I will have to check running the same script in different environment and see if it gets the required output and I shall come back again and I understand this is a forum where I can be of some helping hands like you and may I be creeping a bit but soon I would develop myself reading this forum and thanks leaving your input again I do not have to have the exit part and much thanks again taking more time helping out beginners and sharing your knowledge, Cheers.
== > Connection
oracle@ark#cat someScript
awk "/$1 $2/,/$3 $4/" alert_freeze.log | sed '$d' > thisLog
oracle@ark#./someScript Apr 11 Apr 12
Raja
[Updated on: Tue, 16 April 2013 09:55] Report message to a moderator
|
|
|
|
Re: Shell Script to extract "Particular Content" from a Text File. [message #582286 is a reply to message #582285] |
Tue, 16 April 2013 10:10 |
|
raja_dba
Messages: 33 Registered: November 2012 Location: India
|
Member |
|
|
Mahesh,
I am in home at the moment and I shall post you the version while I reach office tomorrow. I'd really appreciate people like Michel Cadot, BlackSwan, John Watson and not to forget my country owned Mahesh for making this forum much knowledgeable and just to let you know I was a search analyst for about 5 years and I worked both for the british and the americans and while the contracts expired I become jobless and learned Oracle DBA, passed the international certification OCP and now working as a DB Admin in a product based company, Chennai.
Its my carrier change and most the things were pretty new for me, I was not too techie and all I did in the previous was totally different, when I look into the past, it kinda hurts and learning at this point of time to improve my carrier level on the DBA stuff, its more painful but then the other side I find it interesting and I believe with all the helping hands I would improve as possible as I can and tune myself for a better future.
Raja
[Updated on: Tue, 16 April 2013 10:10] Report message to a moderator
|
|
|