Friday, 22 July 2016

A complete script to look for ORA- errors in the Oracle alert log file on Linux Database Server



Title :
A complete script to look for ORA- errors in  the Oracle alert log file on Linux Database Server.

Comment: 

Every now and again ORA- errors crop up and it’s really important to take care them  as soon as possible.

This is the reason why I decided to get a shell script that does it for me automatically.

Following you’ll find the complete script file. It’s only necessary to copy and paste it onto your server .

You can execute it as you wish using the Linux cron daemon, can’t you ?

It is necessary to pass the absolute path of the Oracle alert log file and what’s more the Oracle instance name for example :

./alertlog.sh  /u01/app/oracle/diag/rdbms/dev/trace/alert_DEV.log DEV

NB : As usual it’s always better to look at it on a test environment and then enable on a production environment.  

File : alertlog.sh

#!/bin/bash

what="${1}"
format="+%a %b %d %H:%M"
pattern="ORA-"
logfile="${what}"
tempfile=/home/oracle/dbascript/tempfile/alertlog.tmp.${2}
alertlogtail=/home/oracle/dbascript/tempfile/alertlog.tail.${2}

if [ -s "${logfile}" ] ; then
    diff "${logfile}" "${alertlogtail}" > "${tempfile}"
    grep -n -a "${pattern}" "${tempfile}" > "${tempfile}".out
    if [ -s "${tempfile}".out ] ; then
        what="$(basename $0 | cut -d'.' -f1 )"
        rm "${tempfile}".page.out
        grep -n -a "${pattern}" "${tempfile}" > "${tempfile}".page.out
        if [ -s "${tempfile}".page.out ] ; then
           people="dba@world.it"
        else
           people=" dba@world.it "
        fi

        echo $(date) 'ALERTLOG problems e-mailed to: ' "${people}" >> /home/oracle/dbascript/tempfile/${2}.txt

        mail -s "ALERT: ${2} $(date)" "${people}" < "${tempfile}".out

    fi
#save last run time
    cp "${logfile}" "${alertlogtail}"
fi


See you in my next blog

Byeeee

No comments:

Post a Comment