Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shell script

ABU JAMANFeb 26 2024

Hi all,

I constructed below shell script that reads alert log and then send out email. I debugged the script and it does not show errors but the script dont show any output and email. I appreciate if someone could help.

####################################################################################################

#!/bin/bash
#########################################################################################
# Description: Read each Oracle Home directory. Run adrci matching for problems

# crontab : # Check Alert Log 30.03.2014
# 00,30 * * * * /home/oracle/tmp/adrci_alert.sh > /home/oracle/tmp/adrci.cron.log 2>&1

#########################################################################################
# Which HOME?
export ORACLE_HOME=/orahome/app/oracle/product/19.0.0/dbhome
export DIAG_LOC=/orahome/app/oracle/diag/rdbms
# Who gets the alert?
export RECIPIENT='*******@adp.com'
# Other Variables
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export HOST=`hostname`
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export SUBJECT="Oracle ALERTS on ${HOST} OK"
export LOG=/tmp
export ALERT=$LOG/error.txt

# Write the alert log message header for the email
echo "${HOST} `date +%Y-%m-%d.%H:%M:%S-%Z`" > ${ALERT}
echo "All alerts in ADRCI Alert log for the last 30 minutes" >> ${ALERT}
echo "THIS ALERT WILL NOT BE REPEATED!!! TAKE ACTION NOW!!!" >> ${ALERT}
echo "Follow-up on this email and check the alert log on ${HOST}" >> ${ALERT}

# find out the homes
adrci_homes=( $(adrci exec="show homes" | grep -e rdbms -e asm))

# run through Each home found and examine the alert log
# Here we are looking for ORA- messges, Deadlock, anything which raises an incident or anything which is instance-level
# IN THE LAST 30 MINUTES (1/48), so we need to run this code every 30 minutes or we may miss something.
for adrci_home in ${adrci_homes[@]}
do
echo "Checking: ${adrci_home}" >> ${ALERT}
echo $adrci_home' Alert Log' >> ${ALERT}
adrci exec="set home ${adrci_home} ; show alert -p \\\"(message_text like '%ORA-%' or message_text like '%WARNING%' or message_text like '%instance%' or message_text like '%incident%') and originating_timestamp>=systimestamp-(1/48) \\\"" -term >>${ALERT}
done
# count the errors. This is a good place to exclude specific errors you wish to ignore with a -v match.
# note - your grep must be aligned with the pattern match above for this to work
num_errors=`grep -c -e 'TNS' -e 'ORA' -e 'WARNING' -e 'instance' -e 'incident' ${ALERT} | grep -v 'ORA-28'`

# If there are any errors, lets email the alert information to someone
if [ $num_errors -gt 0 ]
then
SUBJECT="ERROR in Oracle ALERT log on ${HOST}"
mail -s "${SUBJECT}" ${RECIPIENT} < ${ALERT}
fi

Comments
Post Details
Added on Feb 26 2024
2 comments
393 views