Tuesday 26 May 2020

Crontab - Tablespace threshold Alert om mail example


######### Tablespace Threshold Alert ###################

Crontab Details:

0,15,30,45 * * * * /u04/MasterDB/scripts/daily_health_check/tablespace_threshold.ksh > /u04/MasterDB/scripts/daily_health_check/ts_alert.log  2>&1

Scripts Details:

oracle@test02:~> cat /u04/MasterDB/scripts/daily_health_check/tablespace_threshold.ksh

#!/bin/sh

export ORACLE_HOME=/u02/app/oracle/product/12.1.0/dbhome_1

export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

export ORACLE_SID=PRODB

cd /u04/MasterDB/scripts/daily_health_check

logfile=/u04/MasterDB/scripts/daily_health_check/Tablespace_alert.log

cnt1=`ps -ef|grep pmon|grep $ORACLE_SID|wc -l`

if [ $cnt1 -eq 1 ];

then

sqlplus -s "/as sysdba" > /dev/null << EOF

spool $logfile

@/u04/MasterDB/scripts/daily_health_check//tablespace_alert.sql

spool off

exit

EOF

# If there are more then these two lines in the output file, mail it.

count=`cat $logfile|wc -l`

#echo $count

if [ $count  -ge 4 ];

 then

  mailx -s "ALERT: 90 % Threshold Alert FOR PROD Database  "coredba@abc.com <$logfile

fi

fi

oracle@test02:~>

Crontab - Daily Tablespace Check output on mail

#### Tablespace Alert ###############


Crontab Details :

This schecduled scripts will check after every 12 hrs 

0 */12 * * * /u04/MasterDB/scripts/daily_health_check/tablespace_details.sh

Script Output:

oracle@test02:~> cat /u04/MasterDB/scripts/daily_health_check/tablespace_details.sh

#*******DR HOURLY STATUS REPORT*******

#

# Prepared by VARUN YADAV.

#

#*************************************

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Setting Oracle Environment Variables

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

. /home/oracle/.bash_profile



DR_log1=/u04/MasterDB/scripts/daily_health_check/tb_check.log



printf "to:abc@abc.com\n" > $DR_log1

#printf "cc:core_oradba@mind-infotech.com\n" >> $DR_log1

printf "subject: PRODB Tablespace HOURLY STATUS REPORT\n" >> $DR_log1



#printf "\nDR Status report for `uname -n` at `date` \n" >> $DR_log1



sqlplus -s "/as sysdba" <<EOF >> $DR_log1

et echo off

set feed off

set verify off

set serverout on

set wrap off

set pages 300

set lines 200

col file_name for a50

col name for a50

col member for a50

col file_id for a5

col "Percent Used" for a20

col segment_name for a30

col tablespace_name for a60

col STATUS for a16

col owner for a20

col table_name for a35

col index_name for a35

col owner for a20

col object_type for a20

col object_name for a30



COLUMN TABLESPACE FORMAT A25



select name DBNAME from v\$database;



prompt =======================================================================

prompt                       TABLESPACE   UTILIZATION

prompt =======================================================================



select t.tablespace,  t.totalspace as " Totalspace(MB)",

round((t.totalspace-nvl(fs.freespace,0)),2) as "Used Space(MB)",

nvl(fs.freespace,0) as "Freespace(MB)",

round(((t.totalspace-nvl(fs.freespace,0))/t.totalspace)*100,2) as "%Used",

round((nvl(fs.freespace,0)/t.totalspace)*100,2) as "% Free"

from

(select round(sum(d.bytes)/(1024*1024)) as totalspace,d.tablespace_name tablespace

from dba_data_files d

group by d.tablespace_name) t,

(select round(sum(f.bytes)/(1024*1024)) as freespace,f.tablespace_name tablespace

from dba_free_space f

group by f.tablespace_name) fs

where t.tablespace=fs.tablespace (+)

order by t.tablespace



/



prompt ========================================================================

prompt                           Tablespace  More Than 85% used

prompt ========================================================================



select t.tablespace,  t.totalspace as " Totalspace(MB)",

round((t.totalspace-nvl(fs.freespace,0)),2) as "Used Space(MB)",

nvl(fs.freespace,0) as "Freespace(MB)",

round(((t.totalspace-nvl(fs.freespace,0))/t.totalspace)*100,2) as "%Used",

round((nvl(fs.freespace,0)/t.totalspace)*100,2) as "% Free"

from

(select round(sum(d.bytes)/(1024*1024)) as totalspace,d.tablespace_name tablespace

from dba_data_files d

group by d.tablespace_name) t,

(select round(sum(f.bytes)/(1024*1024)) as freespace,f.tablespace_name tablespace

from dba_free_space f

group by f.tablespace_name) fs

where t.tablespace=fs.tablespace (+)

and round(((t.totalspace-nvl(fs.freespace,0))/t.totalspace)*100,2) >=85

order by t.tablespace



/





set feedback on

set verify on





prompt ========================================================================

prompt  MOUNTPOINT DETAILS

prompt ========================================================================

!df -h /u01

!df -h /u02

!df -h /u03

!df -h /u04

prompt ========================================================================

prompt  Archive Mountpoint space details

prompt ========================================================================





!df -h /u04/MasterDB/oradata/SMRPRODB/ArchiveLog



prompt ========================================================================

prompt Total size of archive Today

prompt ========================================================================



!du -sh /u04/MasterDB/oradata/PRODB/ArchiveLog

/

EOF

/usr/sbin/sendmail -t < $DR_log1



oracle@test02:~>

Crontab - Physical standby Archive sync details on mail

Crontab - Physical standby Archive sync details on mail 


Crontab Details : 

Check in every 6 hrs and send mail 


0 */6 * * * /u04/MasterDB/scripts/DR_check/dr_check1.sh

Script Output:

oracle@test01:~> cat /u04/MasterDB/scripts/DR_Check/dr_check1.sh

#*******DR HOURLY STATUS REPORT*******
#
# Prepared by VARUN YADAV.
#
#*************************************
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Setting Oracle Environment Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. /home/oracle/.bash_profile
DR_log=/u04/MasterDB/scripts/DR_check/DR_Status.log
DR_log=/u04/MasterDB/scripts/DR_Check/dr_1.log
printf "to:abc@tech.com\n" > $DR_log
#printf "cc:abc@tech.com\n" >> $DR_log
printf "subject:  Server  DR HOURLY STATUS REPORT " >> $DR_log

printf "\nDR Status report for `uname -n` at `date` \n" >> $DR_log

sqlplus -s "/as sysdba" <<EOF >> $DR_log

set lines 200
select name, instance_name,db_unique_name, open_mode, database_role, flashback_on  current_scn,to_char(standby_became_primary_scn) failover_scn from v\$database,v\$instance;
PROMPT
PROMPT
select process,status,sequence# from v\$managed_standby;
PROMPT
PROMPT

PROMPT
SELECT THREAD#, MAX(SEQUENCE#) AS "LAST_APPLIED_LOG" FROM V\$LOG_HISTORY GROUP BY THREAD#;
PROMPT

PROMPT
SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference" FROM (SELECT THREAD# ,SEQUENCE# FROM V\$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V\$ARCHIVED_LOG GROUP BY THREAD#)) ARCH, (SELECT THREAD# ,SEQUENCE# FROM V\$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V\$LOG_HISTORY GROUP BY THREAD#)) APPL WHERE ARCH.THREAD# = APPL.THREAD#;

EOF
/usr/sbin/sendmail -t < $DR_log

oracle@test01:~>


OUTPUT :

DR Status report for test01 at Tue Nov 12 00:00:01 CET 2019

NAME     INSTANCE_NAME    DB_UNIQUE_NAME                      OPEN_MODE        DATABASE_ROLE            CURRENT_SCN               FAILOVER_SCN
--------- ---------------- ------------------------------ -------------------- ---------------- ------------------ ----------------------------------------
PRODB  PRODB_DR     PRODB_DR                                  READ WRITE         PRIMARY               YES                           469372332




PROCESS   STATUS     SEQUENCE#
--------- ------------ ----------
ARCH     OPENING            28118
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
LNS        OPENING            28119
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0

PROCESS   STATUS     SEQUENCE#
--------- ------------ ----------
ARCH     CONNECTED              0
ARCH     CLOSING            28122
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0

PROCESS   STATUS     SEQUENCE#
--------- ------------ ----------
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CONNECTED              0
ARCH     CLOSING            28118
ARCH     CONNECTED              0

31 rows selected.





   THREAD# LAST_APPLIED_LOG
---------- ----------------
             1               28125




    Thread Last Sequence Received Last Sequence Applied Difference
---------- ---------------------- --------------------- ----------
             1                         28125                          28125              0