Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-20-2008, 02:13 AM   #1
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 :

#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 ]
exit 0

/usr/sbin/sendmail << EOM
subject:$(date +%d-%b-%Y-Time:%H:%M:%S) Database Alert log errors

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

Thanks asusual

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

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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.



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 12:38 PM
shell script find a line and the next line (grep?) metalx1000 Programming 5 07-24-2007 08:41 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
Grep pattern first line of a file ericcarlson Linux - Newbie 11 07-20-2004 10:51 AM
Blank line - grep. liguorir Linux - Software 1 04-24-2004 09:03 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 AM.

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