LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2008, 03:13 AM   #1
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Rep: Reputation: 30
Script to grep a line


Dear all,

As a regular act , I need to monitor a file for some specific error messages.


file name is : alert_ORACLE.ora


in the last 1000 lines of the above mentioned file,am exactly looking for some messages like ORA- or ORA.. then the

For example.. a alert log will contain : (errors like this ).. where ORA-07445 is the error am looking for ..then it has to print 3 lines above the error line and 2 lines below the error line.. want to send this output to a mail..


Thu Sep 6 03:39:04 2007
Errors in file /d01/oraprod/proddb/9.2.0/admin/udump/prod_ora_16214.trc:
ORA-07445: exception encountered: core dump [snstimsane()+54] [SIGSEGV] [Address not mapped to object] [0x0] [] []





currently I have this script to count the no of errors :





#!/bin/sh
#script used to monitor the database alert log file


RETURN_CODE=`grep ORA-* /d01/oraprod/proddb/9.2.0/admin/bdump/alert_PROD.log | wc -l`
if [ $RETURN_CODE -eq 0 ]
then
exit 0
else


/usr/sbin/sendmail erp_webmail@ali.com.kw << EOM
FromBA
To:Administrator
subject:$(date +%d-%b-%Y-Time:%H:%M:%S) Database Alert log errors

$(date)
$(echo "PROD - There are $RETURN_CODE errors in Alert log")





Thanks asusual


Yusuf
 
Old 04-20-2008, 03:44 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
grep -A 2 -B 3 ORA-* /d01/oraprod/proddb/9.2.0/admin/bdump/alert_PROD.log
Of course you need to get rid of the wc for that to make any sense.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep from filename.txt can't get the whole line papasj Programming 3 02-25-2008 01:38 PM
shell script find a line and the next line (grep?) metalx1000 Programming 5 07-24-2007 09:41 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
Grep pattern first line of a file ericcarlson Linux - Newbie 11 07-20-2004 11:51 AM
Blank line - grep. liguorir Linux - Software 1 04-24-2004 10:03 AM


All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration