Search Blog Post

Monday, May 20, 2013

Shell Script for Viewing Alert Log contents from adrci

 # Name script         : show_alertlog_adrci.sh
# Version             : 1.0
# Date                : 20130520
# Author              : Ankur Tyagi    
# Description         : script to display contents of alert log of rdbms
# Parameters(optional):  n : To display number of Last n Line
# Suitable for        : >= Oracle11g
# Execute             : call this
#                       for example: $ ./show_alertlog_adrci.sh 100
#                       => show last 100 lines from rdbms alert log


#!/bin/bash
Daily_Log=/tmp/alert_log_check_daily.txt
MAIL_SUBJ="PROD:WARNING HOST: "
MAIL_RECIPIENT="tyagi.ankur07@gmail.com"
HOST_NAME=`hostname -a`

num_last_line=$1
#shows alert log tail from adrci
$ORACLE_HOME/bin/adrci exec="show homes"|grep rdbms | while read file_line
do
  echo "################################################################################"
  echo " adrci alert log contents " $file_line >> $Daily_Log
  echo "#################################################################################"
  #adrci exec="set homepath $file_line;show alert -tail -f"
  adrci exec="set homepath $file_line; show alert -p \\\"message_text like '%ORA-%' and originating_timestamp > systimestamp-1\\\" $num_last_line"
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 < $Daily_Log
                fi

No comments:

Post a Comment