LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-20-2008, 10:57 AM   #1
dxangel
Member
 
Registered: Nov 2008
Location: London, UK
Distribution: CentOS, RedHat, Ubuntu
Posts: 79

Rep: Reputation: 18
oracle alert log script


Hello, new here, please be nice!

Ive been writing a script to detect application errors in our oracle server (ORA-XXXX) and email me the results. While ive managed to get the basics of it working, i havent managed to figure out how to get my script to remember where it 'left off' so it does not keep picking up old errors ( the alert.log is not rotated )


Code:
#!/bin/sh

#GLOBS

ALERT="ORA-00060";
LOGFILE=/path/to/my/alert_X.log
MYFILE=/home/user/test.log
##


#get the errors out of the logfile.
grep -h "$ALERT" $LOGFILE >> $MYFILE

#count number of lines in myfile, and print.
VAR=`wc -l $MYFILE | awk -F" " '{print $1}'`
#echo $VAR

# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear.

size=0
if [[ $VAR -gt $size ]] ; then

cat $MYFILE | mail -vs "oralert" email@domain.com ;

else
echo "All clear.."


fi;

rm test.log
touch test.log
I would like to run this out of cron ideally.

So i think my options are

- tail ( unreliable as amount of lines generated in any time period is variable
- time ( no idea how to do this! )
- line count ( some idea - perhaps script can check $MYFILE , count line numbers, run the script, then compare line numbers after script has run for difference.. but seems long-winded.

Can anyone please be able to shed some light on which is the best way to go about this?

Thanks v. much in advance.

Last edited by dxangel; 11-20-2008 at 11:09 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-20-2008, 11:33 AM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by dxangel View Post
Hello, new here, please be nice!

Ive been writing a script to detect application errors in our oracle server (ORA-XXXX) and email me the results. While ive managed to get the basics of it working, i havent managed to figure out how to get my script to remember where it 'left off' so it does not keep picking up old errors ( the alert.log is not rotated )
Well, you can do fancy things with saving pointers, looking at the times, etc. Or you could rotate the log with your script, like this:

- Check the log for errors, report and mail them (as you do now).
- COPY the existing log file to another 'archive' directory, named with time/date (for auditing/archival purposes, if you need them later)
- cat /dev/null > <your log file name> (zero it out, so you start over)

Since you've got your old log file info elsewhere, and since the zero-out happens last after you've checked for errors, this will let you keep the old info, but only report on the new.
 
Old 11-20-2008, 11:56 AM   #3
dxangel
Member
 
Registered: Nov 2008
Location: London, UK
Distribution: CentOS, RedHat, Ubuntu
Posts: 79

Original Poster
Rep: Reputation: 18
thank you so much for your reply, and yes ive just figured out something along those lines.


Code:
#!/bin/sh

#GLOBS

ALERT="ORA-00060";
LOGFILE=/path/to/my/alert_X.log
MYFILE=/home/user/test.log
##


#get the errors out of the logfile.
grep -h "$ALERT" $LOGFILE >> $MYFILE

#count number of lines in myfile, and print.
VAR=`wc -l $MYFILE | awk -F" " '{print $1}'`
#echo $VAR



# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear.

#size variable is the number of errors the last time the script ran

size=`wc -l test.last | awk -F" " '{print $1}'`
echo $size

# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear

if [[ $VAR -gt $size ]] ; then

cat $MYFILE | mail -vs "oralert" user@domain.com ;

else
echo "All clear.."


fi;

rm test.last
mv test.log test.last
touch test.log
So as you can see, once its run once, it will keep track of the number of errors from last time it ran and compare. Does this sound OK?
 
Old 11-20-2008, 01:28 PM   #4
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by dxangel View Post
thank you so much for your reply, and yes ive just figured out something along those lines.


Code:
#!/bin/sh

#GLOBS

ALERT="ORA-00060";
LOGFILE=/path/to/my/alert_X.log
MYFILE=/home/user/test.log
##


#get the errors out of the logfile.
grep -h "$ALERT" $LOGFILE >> $MYFILE

#count number of lines in myfile, and print.
VAR=`wc -l $MYFILE | awk -F" " '{print $1}'`
#echo $VAR



# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear.

#size variable is the number of errors the last time the script ran

size=`wc -l test.last | awk -F" " '{print $1}'`
echo $size

# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear

if [[ $VAR -gt $size ]] ; then

cat $MYFILE | mail -vs "oralert" user@domain.com ;

else
echo "All clear.."


fi;

rm test.last
mv test.log test.last
touch test.log
So as you can see, once its run once, it will keep track of the number of errors from last time it ran and compare. Does this sound OK?
Hey, it's your show...if you're happy with it, that's all that matters.
 
Old 02-23-2014, 10:17 AM   #5
haballan
LQ Newbie
 
Registered: Feb 2014
Posts: 1

Rep: Reputation: Disabled
ALERTLOG monitoring script

The following script written in this post can do all what you have asked for, it can monitor all databases and all listeners running on the same server in one shot, and it reports the errors one time only without replicate sending the same email for the same error like other scripts, unless the error it self appear again in the alertlog:
dba-tips.blogspot.ae/2014/02/database-monitoring-script-for-ora-and.html
 
2 members found this post helpful.
Old 02-23-2014, 10:33 AM   #6
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by haballan View Post
The following script written in this post can do all what you have asked for, it can monitor all databases and all listeners running on the same server in one shot, and it reports the errors one time only without replicate sending the same email for the same error like other scripts, unless the error it self appear again in the alertlog:
dba-tips.blogspot.ae/2014/02/database-monitoring-script-for-ora-and.html
Yes...things probably have progressed in the SIX YEARS since this thread was closed.
 
Old 02-23-2014, 11:00 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,947
Blog Entries: 54

Rep: Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732
Quote:
Originally Posted by TB0ne View Post
Yes...things probably have progressed in the SIX YEARS since this thread was closed.
At least he made an effort to share something. What have you contributed to LQ lately that could be marked unequivocally as positive and constructive I wonder?


Quote:
Originally Posted by haballan View Post
The following script written in this post can do all what you have asked for
Your script looks nice. One thing is it's using fixed temporary file names. Please consider fixing that using 'mktemp' or your preferred alternative.
 
2 members found this post helpful.
Old 02-23-2014, 01:17 PM   #8
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by unSpawn View Post
At least he made an effort to share something. What have you contributed to LQ lately that could be marked unequivocally as positive and constructive I wonder?
A quick look reveals a good bit....and the same can be asked of you, especially in light of this comment, and some of the similar snotty ones you make towards others.

And wasn't it you who posted this?
Quote:
Originally Posted by unSpawn
From now on please keep posts on topic, constructive and free from anything that doesn't contribute to the topic at hand or that could be construed as incitive, condescending, childish or anything else non-technical or comms-wise we could do without. Thanks in advance.
Or does that not apply to you??
Quote:
Your script looks nice. One thing is it's using fixed temporary file names. Please consider fixing that using 'mktemp' or your preferred alternative.
Yes, the script does look nice...yet it was necroposted, and won't get the exposure it deserves. Plus, it is a link to his own blog.
 
Old 02-25-2014, 11:47 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,947
Blog Entries: 54

Rep: Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732Reputation: 2732
Quote:
Originally Posted by TB0ne View Post
A quick look reveals a good bit....and the same can be asked of you, especially in light of this comment, and some of the similar snotty ones you make towards others.
If you're concerned about that please address that in a separate thread or email to me or Jeremy. Not here, as we're not discussing how I express myself as fellow LQ member, I'm asking you to mind how you express yourself.

I know you can do that.
 
Old 02-25-2014, 11:56 AM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux
Posts: 2,766
Blog Entries: 1

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
That really is a nice script. I'd like to see that ported to Mysql,.. you happen to have one of those as well?
 
Old 02-25-2014, 12:20 PM   #11
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by unSpawn View Post
If you're concerned about that please address that in a separate thread or email to me or Jeremy. Not here, as we're not discussing how I express myself as fellow LQ member, I'm asking you to mind how you express yourself.

I know you can do that.
Funny, I was also asking YOU to mind how you express yourself...but I should do it in an email to you personally? Thanks, but no.

Take your own advice.
 
Old 02-25-2014, 12:34 PM   #12
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by szboardstretcher View Post
That really is a nice script. I'd like to see that ported to Mysql,.. you happen to have one of those as well?
The MySQL Enterprise Monitor is worth it, if you have the $$$ to invest. I've used this one:

http://bash.cyberciti.biz/monitoring...-shell-script/

...as a base before. I've also used some of the existing MySQL plugins for Nagios, too...they're just perl scripts, and easy to modify. Instead of shoveling things to Nagios, replace with the notification method of your choice.
 
1 members found this post helpful.
Old 02-25-2014, 12:39 PM   #13
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux
Posts: 2,766
Blog Entries: 1

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Cool, im going to check out the nagios plugins and see what I can pull out of there. Thanks for the hint!
 
  


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
SSH Alert when root attempts to log gamehack Linux - Software 3 06-03-2009 06:44 AM
Shutdown script possible to alert about connected USB devices? Roy Prins Linux - Newbie 6 07-23-2008 06:47 AM
Oracle 9i Alert logs cmontr Linux - General 3 12-11-2007 05:21 PM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 04:19 AM
snort not logging port scans? Should I use log or alert? lucastic Linux - Security 3 08-30-2004 04:34 AM


All times are GMT -5. The time now is 12:18 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration