Sunday, April 11, 2021

 DB2 HADR monitor script - V10.5

Schedule the below script in cron to get email alerts.

#!/usr/bin/ksh

<<Comment_here

Script for DB2 HADR monitor - PRD.

S.M.Gopinath

Comment_here


cd /db2/db2inst1/scripts/monitor_hadr


email_id="<your email id>"

>monitor_hadr.out

#Sourcing the db2profile:


if [ -f ${HOME}/sqllib/db2profile ]; then

    . ${HOME}/sqllib/db2profile

else

    echo "db2profile not found at ${HOME}/sqllib/ directory, please check for db2profile"

fi


db2 +e +o "connect to prd"

db2 +o -z monitor_hadr.out -txf monitor_hadr.sql

db2 +e +o "connect reset"


if [ -s monitor_hadr.out ]; then

#Sending the report email:

 mail -s "PRD HADR status - $(date)" ${email_id} <<- Hadr_status

 $(sed 's/,/\n/g' monitor_hadr.out)

Hadr_status


else

 mail -s "PRD HADR status - $(date)" ${email_id} <<- Hadr_status

 Unable to monitor HADR status

Hadr_status

fi

####################End of script####################