Script for monitoring with ADRCI utility in Oracle

Script for monitoring with ADRCI utility in Oracle

Following is the script used for monitoring with help of ADRCI utility. It will generate or report error and incident coming in Listener.log and alert.log files.

Script:

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

###### ALERT LOG CHECKING VIA ADRCI #############
#################################################
# To run for last 24 hours - ./check_alert.sh D
# To run for last hour - ./check_alert.sh
# Edit variables below for moving between servers
# Changes To the Script
#

export ORACLE_SID=+ASM1
export ORACLE_HOME=/u01/crs/oracle/product/11.2.0/grid/
export PATH=$PATH:$ORACLE_HOME/bin
DAILY_LOG=/home/oracle/bin/alert_log_check_daily.txt
HOURLY_LOG=/home/oracle/bin/alert_log_check_hourly.txt
MAIL_SUBJ="PRD:WARNING HOST: "
MAIL_RECIPIENT="your_dba_group@your_company.com"

HOST_NAME=`hostname -a`

if [ "$1" = "D" ]
then

############################################
###############DAILY CHECKS ################
############DBMS AND ASM CHECK##############
############################################

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

echo '####################################################' > $DAILY_LOG
echo '####### ALERT LOG OUTPUT FOR LAST 24 HOURS #########' >> $DAILY_LOG
echo '####################################################' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG

for adrci_home in ${adrci_homes[@]}
do
echo $adrci_home' Alert Log' >> $DAILY_LOG
adrci exec="set home ${adrci_home};

show alert -p \\\"message_text like '%ORA-%' and originating_timestamp > systimestamp-1\\\"" -term >> $DAILY_LOG
done

############################################
############## DAILY CHECKS ################
############# LISTENER CHECK###############
############################################

adrci_lsnr_homes=( $(adrci exec="show homes" | grep -e tnslsnr))

echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '####################################################' >> $DAILY_LOG
echo '###### LISTENER LOG OUTPUT FOR LAST 24 Hours #######' >> $DAILY_LOG
echo '####################################################' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG
echo '' >> $DAILY_LOG

for adrci_lsnr_home in ${adrci_lsnr_homes[@]}
do
echo $adrci_lsnr_home' Listener Log' >> $DAILY_LOG
adrci exec="set home ${adrci_lsnr_home}; show alert -p \\\"message_text like '%TNS-%' and originating_timestamp > systimestamp-1\\\"" -term >> $DAILY_LOG
done

num_errors=`grep -c -e 'TNS' -e 'ORA' $DAILY_LOG`
if [ $num_errors != 0 ]
then
MAIL_SUBJ=$MAIL_SUBJ$HOST_NAME" Errors Found in Daily Alert Summary"
mailx -s "$MAIL_SUBJ" $MAIL_RECIPIENT $HOURLY_LOG
echo '' >> $HOURLY_LOG
echo '' >> $HOURLY_LOG
echo '####################################################' >> $HOURLY_LOG
echo '######### ALERT LOG OUTPUT FOR LAST HOUR ###########' >> $HOURLY_LOG
echo '####################################################' >> $HOURLY_LOG
echo '' >> $HOURLY_LOG
echo '' >> $HOURLY_LOG
echo '' >> $HOURLY_LOG

for adrci_home in ${adrci_homes[@]}
do
echo $adrci_home' Alert Log' >> $HOURLY_LOG
adrci exec="set home ${adrci_home}; show alert -p \\\"message_text like '%ORA-%' and originating_timestamp > systimestamp-1/24\\\"" -term >> $HOURLY_LOG
done

num_errors=`grep -c -e 'TNS' -e 'ORA' $HOURLY_LOG`
if [ $num_errors != 0 ]
then
MAIL_SUBJ=$MAIL_SUBJ$HOST_NAME" Errors Found in Hourly Alert Summary"
mailx -s "$MAIL_SUBJ" $MAIL_RECIPIENT < $HOURLY_LOG
fi

fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.