LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   oracle alert log script (https://www.linuxquestions.org/questions/programming-9/oracle-alert-log-script-684917/)

dxangel 11-20-2008 10:57 AM

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.

TB0ne 11-20-2008 11:33 AM

Quote:

Originally Posted by dxangel (Post 3348830)
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.

dxangel 11-20-2008 11:56 AM

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?

TB0ne 11-20-2008 01:28 PM

Quote:

Originally Posted by dxangel (Post 3348890)
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. :)

haballan 02-23-2014 10:17 AM

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

TB0ne 02-23-2014 10:33 AM

Quote:

Originally Posted by haballan (Post 5123244)
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.

unSpawn 02-23-2014 11:00 AM

Quote:

Originally Posted by TB0ne (Post 5123254)
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 (Post 5123244)
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.

TB0ne 02-23-2014 01:17 PM

Quote:

Originally Posted by unSpawn (Post 5123268)
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.

unSpawn 02-25-2014 11:47 AM

Quote:

Originally Posted by TB0ne (Post 5123319)
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.

szboardstretcher 02-25-2014 11:56 AM

That really is a nice script. I'd like to see that ported to Mysql,.. you happen to have one of those as well?

TB0ne 02-25-2014 12:20 PM

Quote:

Originally Posted by unSpawn (Post 5124443)
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.

TB0ne 02-25-2014 12:34 PM

Quote:

Originally Posted by szboardstretcher (Post 5124448)
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. :)

szboardstretcher 02-25-2014 12:39 PM

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

Lachhman 12-28-2014 03:49 AM

Please suggest me how to add diff critical error in this script.
here in this script u have only defined one ALERT="ORA-00060"; .I tried to add multiple error as same type of error came in my alert log so i can easily rectify ASAP.Kindly help me add multiple ora error nhn with ALERT="ORA-00060";
Thanks in Advance

unSpawn 12-28-2014 05:31 AM

Quote:

Originally Posted by Lachhman (Post 5291462)
I tried to add multiple error

Then please show us what you've tried and where you got stuck.


All times are GMT -5. The time now is 04:52 AM.