DOYENSYS Knowledge Portal




We Welcome you to visit our DOYENSYS KNOWLEDGE PORTAL : Doyensys Knowledge Portal




Thursday, November 27, 2014

ASM Diskgroup free space check script

#!/bin/bash
###############################################################################
# File Name   : asmdiskgroup_free_space.sh
# Author      : Vimal Raju
# Date        : 27/11/2014
# Description : asmdiskgroup size check
#
###############################################################################
#############################################################
#
# Display usage infommation
#
usage () {

  echo " "
  echo " Checking the asmdiskgroup free space "
  echo "       -h Display this message"
  echo "       -e specify the environment file with location (Mandatory) (Example : /home/oracle/db.env ) "
  echo "       -m specify the email address (Mandatory) (Example : test@gmail.com ) "
  echo "       -p Specify the Percentage of the asmdiskgroup size check (default : 80 )"
  echo "       -l Specify the Log file location (default : /tmp )  "
  echo "     Example : asmdiskgroup_free_space.sh -e /home/oracle/db.env -m support@doyensys.com "

  exit 1

}

validate() {

INDFILE=${LOG_LOC}/tablepace_size_check.ind
  # To check if the indicator file is there
  if [ -f ${INDFILE} ]; then
    echo "Indicator file ${INDFILE} exists!"
    exit 1
  else
    touch ${INDFILE}
  fi

  if [ ${#ENV_FILE} -eq 0 ]; then
    echo "No Environment file name specified!"
    usage
  fi

  if [ ${#MAIL_TO} -eq 0 ]; then
    echo "No Mail address specified!"
    usage
  fi

  if [ -f ${LOG_LOC}/asmdiskgroup_trigger_tmp.log ]; then
    echo ""
  else
    touch ${LOG_LOC}/asmdiskgroup_trigger_tmp.log
  fi

  if [ -f ${LOG_LOC}/asmdiskgroup_trigger.log ]; then
    echo ""
  else
    touch ${LOG_LOC}/asmdiskgroup_trigger.log
  fi

  if [ -f ${LOG_LOC}/asmdiskgroup_check.log ]; then
    echo ""
  else
    touch ${LOG_LOC}/asmdiskgroup_check.log
  fi

}

asmdiskgroup() {

sqlplus -s / as sysdba <<EOF
set feed off
SET LINESIZE  145
SET PAGESIZE  9999
SET VERIFY    off
spool ${LOG_LOC}/asmdiskgroup_check.log
COLUMN group_name             FORMAT a20           HEAD 'Disk Group|Name'
COLUMN sector_size            FORMAT 99,999        HEAD 'Sector|Size'
COLUMN block_size             FORMAT 99,999        HEAD 'Block|Size'
COLUMN allocation_unit_size   FORMAT 999,999,999   HEAD 'Allocation|Unit Size'
COLUMN state                  FORMAT a11           HEAD 'State'
COLUMN type                   FORMAT a6            HEAD 'Type'
COLUMN total_mb               FORMAT 999,999,999   HEAD 'Total Size (MB)'
COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'
COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'
Select * from (SELECT
    name                                     group_name
  , sector_size                              sector_size
  , block_size                               block_size
  , allocation_unit_size                     allocation_unit_size
  , state                                    state
  , type                                     type
  , total_mb                                 total_mb
  , (total_mb - free_mb)                     used_mb
  , ROUND((1- (free_mb / total_mb))*100, 2)  pct_used
FROM
    v\$asm_diskgroup
ORDER BY
    name
) where pct_used > ${PERCENTAGE}  ;
spool off
EOF

trig=`cat ${LOG_LOC}/asmdiskgroup_check.log|wc -l`
check_tmp=`cat ${LOG_LOC}/asmdiskgroup_trigger_tmp.log`

if [ "${trig}" != 0 ]
then
echo C > ${LOG_LOC}/asmdiskgroup_trigger.log
elif [ "${check_tmp}" = 'T' ]
then
echo N > ${LOG_LOC}/asmdiskgroup_trigger.log
fi

check_crit=`cat ${LOG_LOC}/asmdiskgroup_trigger.log `
if [ "${check_crit}" = 'C' ]
then
cat ${LOG_LOC}/asmdiskgroup_check.log|mailx -s "Critical : ASM DISK GROUP Total allocated > ${PERCENTAGE}" $MAIL_TO
echo T > ${LOG_LOC}/asmdiskgroup_trigger_tmp.log
elif [ "${check_crit}" = 'N' ]
then
cat ${LOG_LOC}/asmdiskgroup_check.log|mailx -s "Normal : ASM DISK GROUP Total allocated < ${PERCENTAGE}" $MAIL_TO
echo "" > ${LOG_LOC}/asmdiskgroup_trigger.log
echo "" > ${LOG_LOC}/asmdiskgroup_trigger_tmp.log
fi

}


PERCENTAGE=80
LOG_LOC=/tmp
ENV_FILE=
MAIL_TO=

while getopts :hp:l:e:m: opt $*
    do
      case $opt in
        h) usage
           ;;
        p) PERCENTAGE=${OPTARG}
           echo PERCENTAGE set to ${PERCENTAGE}
           ;;
        l) LOG_LOC=${OPTARG}
           echo LOG_LOC set to ${LOG_LOC}
           ;;
        e) ENV_FILE=${OPTARG}
           echo ENV_FILE set to ${ENV_FILE}
           ;;
        m) MAIL_TO=${OPTARG}
           echo MAIL_TO set to ${MAIL_TO}
           ;;
        *) echo "******************************************************************"
           echo "${JOBNAME}: Invalid option found on command line: ${OPTARG}"
           echo "******************************************************************"
           usage
           ;;
      esac
    done


validate

. $ENV_FILE

asmdiskgroup

if [ -f ${INDFILE} ]; then
      rm -f ${INDFILE}
fi

1 comment:

Sridevi K said...

Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, SQL, PL/SQL, D2K at training@oracleappstechnical.com | +91 - 9581017828.