#!/usr/bin/ksh

# source the database instance to be monitored like ORACLE_SID, ORACLE_BASE, ORACLE_HOME … saved by you to a .profile

$ORACLE_HOME/bin/sqlplus “/ as sysdba” << eof set echo off set trim on set trims on set verify off spool $ORACLE_BASE/log/errors.log select distinct originating_timestamp, message_text from x\$dbgalertext where (originating_timestamp >= sysdate-120/1440)
and (message_text like ‘%ORA-%’ or message_text like ‘%Fatal%’ or message_text like ‘%Errors%’ or message_text like ‘%Corrupt%’ or message_text like ‘%event%’);

spool off
eof
exit

ErrCnt=`cat $ORACLE_BASE/log/errors.log |grep “no rows selected”| wc -l`

if [[ $ErrCnt == “1” ]]
then
echo “we are good”
else
uuencode $ORACLE_BASE/log/errors.log $ORACLE_BASE/log/errors.log|/usr/bin/mailx -s “$ORACLE_SID on $host has errors” “$MAIL”
fi