To Check ORA-Error on Oracle Database using Shell Scripts on Solaris/Unix.
Following Scripts will check ORA Error and send alert on mail.
#!/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/ ORCL.env
. /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 scripts checks for any ORA errors at alert log file and if found any ORA error send an alert e-mail.
Schedule it with crontab to run every 20 minutes to check error.
