Shell Scripts

[Shell Script] – Sends email alert if Oracle sessions count exceeds 250

#!/bin/ksh
####################################################################
#       Script Name     :      sessions_count_check.ksh
#       Date            :      02-SEP-2019
#       Author          :      DBA Team
#       Description     :      Sends report if session count exceeds 250
###################################################################
#
#------------------------------------------------------------------
# Initialization
#------------------------------------------------------------------
    ORACLE_SID=$1; export ORACLE_SID
        UNAME=`uname`
case `uname` in
    "HP-UX" ) ORATAB="/etc/oratab"
              ;;
    "SunOS" ) ORATAB="/var/opt/oracle/oratab"
              ;;
    "Linux" ) ORATAB="/etc/oratab"
              ;;
          * ) ORATAB="/etc/oratab"
              ;;
esac

# Find and Set Oracle Home
ORACLE_HOME=`cat $ORATAB | grep -i "^$ORACLE_SID" | grep -v "^#" | cut -d: -f2`
export ORACLE_HOME

# Set Path
PATH=$PATH:$ORACLE_HOME/bin
export PATH

# Date and Time
DATE=`date +%m/%d/%Y::%H:%M:%S`

export MailId=Your_Mail_Id@gmail.com
export CONTENT="/tmp/sessions_count_check.html"
export SUBJECT="[CRITICAL] : $ORACLE_SID: High number of Sessions on `uname -n`. Please check and communicate to Application team"

sqlplus -s "/ as sysdba" @/scripts/sessions_count_check.sql >/tmp/sessions_count_check.html

strings=`cat /tmp/sessions_count_check.html | grep 'no rows selected' | wc -l`

if [ $strings -ne 1  ]
then
    (
echo "TO :$MailId"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT) | /usr/lib/sendmail -r 'Oracle-DBA' $MailId
fi
/scripts/sessions_count_check.sql :

prompt  <b>Team, please send email to Application team and ask them to check application status</b>
set markup html on
set lines 300 pages 3000
select count() "sessions" from gv$session where username is not null and status='ACTIVE' having(count()) > 250;
select event,count(*) from gv$session where username is not null and status='ACTIVE' group by event order by 2 desc;
exit;
Review
4
Comments Rating 0 (0 reviews)

About the author

BestTechReads

Add Comment

Click here to post a comment

Sending

Categories

Categories