Total Pageviews

Tuesday, February 18, 2020

How To Send Alert Mail For File System Crossing Threshold Limit.


Make directory script as below:

[oracle@myhost]mkdir /home/oracle/script

[oracle@myhost]cd /home/oracle/script

[oracle@myhost script]$ pwd
/home/oracle/script
Script 1) This is the main script which help us to send the alert mail.
[oracle@myhost script]$ vi fs_space_alert.sh
##!/usr/bin/ksh
# =============================================================================
# NAME
#    fs_space_alert.ksh
#
# DESCRIPTION
#    Check UNIX file system free space and send alert to DBA
#
# USAGE
#    ./ts_free_space.ksh
#
# NOTES
#
# HISTORY
#    ashwani/ashwani - 30-APR-106 - Initial version
#
# =============================================================================

#--------------------------------------------------------------------------------------------------
# Variables
#--------------------------------------------------------------------------------------------------
PROGRAM=$( basename $0 )
DIR=$( dirname $0 )
OS=$(uname)
HOST=myhost
INPUT_FS_ALERT=$DIR/input_fs_alert.txt

# source dba related profile ------------------
. $DIR/.dba_profile

#--------------------------------------------------------------------------------------------------
# Main Program
#--------------------------------------------------------------------------------------------------
if [[ ! -f ${INPUT_FS_ALERT} ]];then
    echo "Space alert baseline file not found, creating empty file: ${INPUT_FS_ALERT}"
    touch ${INPUT_FS_ALERT}
    exit 8
fi

exec 3< $INPUT_FS_ALERT
while read -u3 fs pct
do
    if [[ $OS = 'HP-UX' ]];then
        pct_used=`bdf -b ${fs} | grep -v "^Filesystem" | awk '{print $5}' | sed 's/%//g'`
    elif [[ $OS = 'SunOS' ]];then
        pct_used=`df -k ${fs} | grep -v "^Filesystem" | awk '{print $5}' | sed 's/%//g'`
    else
        pct_used=`df -k ${fs} | grep -v "^Filesystem" | awk '{print $4}' | sed 's/%//g'`
    fi


    if [[ ${pct_used} -ge ${pct} ]];then
       echo "!! A C T I O N !! File System ${fs} is ${pct_used} full on $HOST" | /bin/mail -s "File System Alert from $HOST !!!  A C T I O N  !!! required"  $DBAMAILLIST
    fi
done
exec 3<&-


Script 2) Below script is used for calculating thresh hold of mount point /home and /u01. When these mount reaches to 30% and 90% respectively we will receive mail once the job triggered from cron.


[oracle@myhost script]$vi input_fs_alert.txt
/home 30
/u01 90



[oracle@myhost ~]$ pwd
/home/oracle
[oracle@myhost ~]$ cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=myhost.mind.motherson.com; export ORACLE_HOSTNAME
ORACLE_UNQNAME=oracle; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
ORACLE_SID=oracle; export ORACLE_SID

PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH


Script 3) Below script will send alert mail to mail id oracleforeinsics4u@gmail.com

[oracle@myhost script]$ vi .dba_profile
. $HOME/.bash_profile
export DIR=/home/oracle/script
export LOGDIR=$DIR/logs

DBAMAILLIST="oracleforeinsics4u@gmail.com"; export DBAMAILLIST


[oracle@myhost script]$ ls -la
total 56
drwxr-xr-x  3 oracle oinstall  4096 Feb 12 20:04 .
drwx------ 48 oracle oinstall 32768 Feb 12 20:04 ..
-rw-r--r--  1 oracle oinstall   141 Feb 12 20:04 .dba_profile
-rw-r--r--  1 oracle oinstall  1811 Feb 12 17:44 fs_space_alert.sh
-rw-r--r--  1 oracle oinstall     9 Feb 12 17:58 input_fs_alert.txt
drwxr-xr-x  2 oracle oinstall  4096 Feb 12 17:56 logs
[oracle@myhost script]$ cat .dba_profile
. $HOME/.bash_profile
export DIR=/home/oracle/script
export LOGDIR=$DIR/logs

DBAMAILLIST="oracleforensics4u@gmail.com"; export DBAMAILLIST


[oracle@myhost script]$ ls -lrth
total 12K
-rw-r--r-- 1 oracle oinstall 1.8K Feb 12 17:44 fs_space_alert.sh
drwxr-xr-x 2 oracle oinstall 4.0K Feb 12 17:56 logs
-rw-r--r-- 1 oracle oinstall    9 Feb 12 17:58 input_fs_alert.txt

[oracle@myhost script]$ crontab -l
00 20 * * * sh /home/oracle/script/fs_space_alert.sh

No comments:

Post a Comment