#!/bin/ksh export PAGE_THRESHOLD=$1 export DB=$2 export ARCH_DG=$3 # ------------------------------------------------------------------------------------------ # INITIAL SETUP # ------------------------------------------------------------------------------------------ export FN=`echo $0 | sed s/\.*[/]//` echo "Filename: $FN" export ORACLE_BASE=`grep -i ^oracle: /etc/passwd | cut -d: -f6` . $ORACLE_BASE/general/sh/functions.ksh set_basics; # ---------------------- # CONFIGURATION SECTION # ---------------------- # Ksh version issue # So enter it again here #----------------------------------------------- export FILENAME=$(basename $0 |awk -F"." {'print $1'}) export CONFIG_FILE="${SH}"/"${FILENAME}".conf export CONTROL_FILE="${SH}"/"${FILENAME}".ctl source_config_file; get_rodba_prefix; set_oratab; #--------------------------------------------------------------------- # Setup the Oracle Environment and pass the ORACLE_SID #--------------------------------------------------------------------- [ -d /var/opt/oracle/bin ] && export BINDIR=/var/opt/oracle/bin || export BINDIR=$HOME/general/sh/bin . $BINDIR/oracle_setup.ksh `$BINDIR/getsid.ksh` export CONNECT_STRING=rodba/${RODBA_PREFIX}@${DB} #print "Connect String: $CONNECT_STRING" #--------------------------------------------- # Parameters from the ${0}.conf file # And define error and log files #--------------------------------------------- export LOGDIR=${TMPDIR} export LOGFILE=${LOGDIR}/${DB}_dg_arch_free_email_notif.alert if [ -f "$LOGFILE" ]; then rm $LOGFILE fi function show_debug_parameters { echo "Max Number of Alerts: $MAX_NUMBER_ALERTS" echo "Log Directory: $LOGDIR" echo $COUNTER } function exam_dg_threshold { export PAGE_THRESHOLD=$1 sqlplus -s $CONNECT_STRING 2>&1 <<__ENDSQL whenever sqlerror exit sql.sqlcode; set pages 60 set lines 90 set verif off set trims on col pct_free for 999.9 hea '%_FREE' define ORA_SID='$DB' define PAGE_THRESHOLD=$PAGE_THRESHOLD define LOG_DIR='$LOGDIR' spool $LOGFILE select name DG_NAME, total_mb/1024 GB, round(free_mb/total_mb,2)*100 pct_free from v\$asm_diskgroup where round(free_mb/total_mb,2)*100 < &PAGE_THRESHOLD and name=upper('$ARCH_DG'); spool off set pages 14 set lines 80 set verif on __ENDSQL grep "DG_NAME" $LOGFILE export RC1=$? grep ORA-00257 $LOGFILE export RC2=$? if [[ "$RC1" -eq 0 || "$RC2" -eq 0 ]]; then (( EMAIL_COUNTER = ${COUNTER} + 1 )) # --------------------------------------------------------------- # Set ALERT_COUNTER to be passed into alert_notification.ksh # --------------------------------------------------------------- export ALERT_COUNTER=$EMAIL_COUNTER print "Sending dgmon Archive Destination alert ... $ALERT_COUNTER for $DB" $SH/alert_notification.ksh ${FN} `hostname` $DB "" "ARCH: Alert#: $EMAIL_COUNTER for Archive Destination Disk Group Free < $PAGE_THRESHOLD percent!" $LOGFILE # Increment the counter by one and append it to the LOGFILE filename (( COUNTER = ${COUNTER} + 1 )) echo $COUNTER mv ${LOGFILE} ${LOGFILE}.${COUNTER} fi } #+++++++++++++++++++++++++++++++++++++++++++++++++++++ # MAIN LOGIC #+++++++++++++++++++++++++++++++++++++++++++++++++++++ #-------------------------------------------- # Count the number of error files (LOGFILE) # in the /tmp directory #-------------------------------------------- if [ -f ${LOGFILE}.* ]; then export COUNTER=$(ls ${LOGFILE}.* |wc -l) else COUNTER=0 fi #show_debug_parameters; #------------------------------------------------------ # If # of error files on disk is greater than # $MAX_NUMBER_ALERTS, then skip to the next database #------------------------------------------------------ if [ "${COUNTER}" -ge "$MAX_NUMBER_ALERTS" ]; then echo "Exceeded Max number of Alerts: $MAX_NUMBER_ALERTS" else exam_dg_threshold $PAGE_THRESHOLD; fi