In this post we will learn how to check ora error on oracle database using shell scripts. We can prepare scripts and schedule to monitor error in alert log., due to this error our database not functioning as expected. To overcome this issue well prepare proactive alert to check the ora error if any.
How to check ora error on oracle database using shell scripts on Solaris/Unix?.
Following Scripts will check ORA Error and send alert on mail. Just follow the below steps to prepare and execute it in shell script. Later you may schedule this script using crontab. After preparing the script we will aware that how to check ora error in oracle.
#!/bin/bash
Emails=”mention email”
message=”******ORA Error@`uname -n` ******”
export message
# an error message is displayed and the script exits with a status of 1
#if [ $1 ]
#then
ORACLE_SID=ORCL; export ORACLE_SID
##Set the Environment##
. /arch/oracle/devora/ora10g/
cd $ORACLE_HOME/admin/ORCL/bdump
# Copy the current alert log into a temporary file and empty the original
tail -10 alert_$ORACLE_SID.log /arch/oracle/orcl/ testscript/logs/alert_$ORACLE_ SID.log.temp
# Check the copy in the temporary file for ORA- errors
grep ORA- /arch/oracle/orcl/ testscript/logs/alert_$ORACLE_ SID.log.temp >> /arch/oracle/orcl/ testscript/logs/ORA_Error.log
grep Shut /arch/oracle/devora/ testscript/logs/alert_$ORACLE_ SID.log.temp >> /arch/oracle/orcl/ testscript/logs/ORA_Error.log
# If found, email the Oracle user with the contents of the alert log
if [ $? = 0 ]
then
mailx -s “$message” $Emails <
/arch/oracle/orcl/ testscript/logs/ORA_Error.log
fi
#Remove the temp file.
rm /arch/oracle/orcl/ testscript/logs/alert_$ORACLE_ SID.log.temp
rm /arch/oracle/orcl/ testscript/logs/ORA_Error.log
This script will check for any ora error in database at alert log file and if it found any ORA error then script will send an alert on e-mail.
Schedule it with crontab to run every 20 minutes to check error.