Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    17

    Unanswered: shell script to check severe error and email and HADR Status andeliminate HADR error

    Hi ,

    I want to write a shell script which will scan the db2 diagnostic log for severe error and send out an email.

    I want to eliminate the HADR error from the script, but need to check the HADR Status. If HADR status is disconnect it should send out an email.

    I have written the script, but don't know how to fit in the HADR logic.

    Could some one help me it will be really great and thanks a lot in advance.

    DB2 version is 9.7 but the script will run in any version as it's just scanning the log and sending an email.

    #!/usr/bin/ksh
    # DB2diag log report severe errors
    # Input parms server instance
    # --------------------------------
    #
    # altered to source db2 profile correctly
    # --------------------------------
    # Parameters:
    # $1 prefix for errors log to make it unique
    # $2 db2 instance to change to

    . /home/db2inst2/sqllib/db2profile

    cd /db2bkup_prod/scripts/

    #FILE=${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors.log

    # Severe errors
    #---------------
    db2diag -l severe -H 15m -readfile > ${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors.log
    db2diag -gvi "Function:=High Availability Disaster Recovery" -l severe -H 1d -readfile > /db2bkup_prod/scripts/diag_check_for_severe_errors_hadr.log

    # Send email
    #---------------------------------------
    dt=`date +"%Y.%m.%d-%H:%M:%S"`
    #echo $dt > ${DB2INSTANCE}/report_diag.txt
    #echo >> ${DB2INSTANCE}/report_diag.txt

    if test ! -s "${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors.log"
    then
    echo ${DB2INSTANCE}/report_diag.txt is empty.
    echo No email sent
    else
    # Get the list of local databases in the instance
    databaseList()
    {
    # List of local databases in the instance.
    dblist=`(db2 list db directory|awk '/Database name/ {db=$4} /Indirect/ {print db}'|sort -u|xargs)`
    #echo $dblist

    }

    # Check the HADR status of databases that are HADR enabled in the instance.
    hadrStatus()
    {
    # Check the HADR status of each database listed
    hadrCount=0
    for db in $dblist
    do
    hadr_role=$(db2 get db cfg for $db |egrep "HADR database role"|awk '{print $5}')

    if [[ $hadr_role != 'STANDARD' ]]; then
    hadrCount=hadrCount+1
    hadrStatusLine=$(db2pd -hadr -d $db|awk '/^Primary |^Standby / {print $0}')
    hadrConnectLine=$(db2pd -hadr -d $db|awk '/^Connected |^Disconnected |^Congested / {print $0}')

    hadrRole=$(echo $hadrStatusLine|awk '{print $1}')
    hadrStatus=$(echo $hadrStatusLine|awk '{print $2}')

    hadrConnect=$(echo $hadrConnectLine|awk '{print $1}')

    if [[ -z $hadrRole && $instStatus == 'active' ]]; then
    echo "Database $db in HADR $hadr_role role but NOT active"
    else
    if [[ $hadrRole == 'Primary' || $hadrRole == 'Standby' ]]; then
    echo " $db :" $hadrRole" "$hadrConnect" "$hadrStatus
    fi
    fi
    fi
    done
    if [ $hadrCount == 0 ]; then
    echo " *** HADR is not enabled for the databases in the instance $inst ***"
    fi
    }


    if test ! -s "${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors_tmp.log"
    then
    subject="DB2Diag log Error check: $1 $2 - Errors found - $dt"
    # Prepare email head
    #----------------------------------------
    to=" "
    cc=" "

    # send email
    #----------------------------------------
    mail -s "$subject" -c "$cc" $to < /db2bkup_prod/scripts/report_diag.txt
    else
    subject="DB2Diag log Error check: $1 $2 - Errors found - $dt"
    # Prepare email head
    #----------------------------------------
    to=" "
    cc=" "

    # send email
    #----------------------------------------
    mail -s "$subject" -c "$cc" $to < /db2bkup_prod/scripts/report_diag.txt
    fi
    # remove email text
    #----------------------------------------
    #rm -rf ${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors.log
    #rm -rf ${DB2INSTANCE}/report_diag.txt
    #rm -rf ${DB2INSTANCE}/$1_$2_diag_check_for_severe_errors_tmp.log

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    the db2pd -hadr command is already present and can check hadr status
    we have a similar script that analyzes db2pd output and can also display lssam info

    if [[ ${db2v} = 'v9' ]]; then
    for I in $dblst; do
    db2pd -d ${I} -hadr | {
    while read TSREC; do
    ((cnt=cnt+1))
    set - $TSREC
    P1=$1 ;P2=$2 ;P3=$3 ;P4=$4 ;P5=$5 ;P6=$6 ;P7=$7 ;P8=$8 ;P9=$9 ;P10=$10
    if [[ ${ENTRY} -eq 1 ]]; then
    Role=$P1
    State=$P2
    Sync=$P3
    Loggap=$P5
    ENTRY=0
    fi
    if [[ ${CENTRY} -eq 1 ]]; then
    Conn=$P1
    ConnT=${P2}_${P3}_${P4}_${P5}_${P6}
    CENTRY=0
    if [[ ${disp} = 'C' ]]; then
    printf "%10s%10s%15s%13s%10s%15s%28s\n" $I $Role $Conn $State $Sync $Loggap $ConnT
    fi
    if [[ ${Conn} != "Connected" ]]; then
    Alert=1
    msg='HADR_status_:_'${P1}'_for_'${hostname}
    fi
    fi
    if [[ ${P1} = "Role" && ${P2} = "State" ]]; then
    ENTRY=1
    fi
    if [[ ${P1} = "ConnectStatus" && ${P2} = "ConnectTime" ]]; then
    CENTRY=1
    fi
    if [[ ${P1} = "HADR" && ${P2} = "is" && ${P3} = "not" && ${cnt} -eq 5 ]]; then
    printf "%10s%21s\n" $I "HADR is NOT ACTIVE"
    fi
    if [[ ${P1} = "Database" && ${P4} = "activated" && ${P3} = "not" && ${cnt} -eq 2 ]]; then
    echo "$I Database is NOT ACTIVATED"
    fi
    done
    }
    if [[ ${lssam} -eq 1 ]] ; then
    lssam |grep "IBM.Application:db2_db2inst1_db2inst1" |grep _${I}
    fi
    cnt=0
    done

    and returns something like
    (0)[db2inst1@plx00006 common]$ ./get_hadr_status.sh -c
    -----------------------------------------------------------------------------------------------
    Database Role Connection Status-State Loggap ConnectTime
    -----------------------------------------------------------------------------------------------
    CLSM Primary Connected Peer Nearsync 66711 Wed_Dec_17_15:11:53_2014
    WPRCSDB Primary Connected Peer Nearsync 11 Wed_Dec_17_15:16:29_2014
    BBPEDB Primary Connected Peer Nearsync 22 Wed_Dec_17_15:09:34_2014
    BMEDB Primary Connected Peer Nearsync 7018 Wed_Dec_17_15:10:21_2014
    BPEDB Primary Connected Peer Nearsync 11 Wed_Dec_17_15:10:46_2014
    LOWAPPL Primary Connected Peer Nearsync 594 Wed_Dec_17_15:14:30_2014
    HIGHPEAK Primary Connected Peer Nearsync 3007 Wed_Dec_17_15:13:36_2014
    MEDB Primary Connected Peer Nearsync 2478 Wed_Dec_17_15:15:06_2014
    SOADB Primary Connected Peer Nearsync 8599 Wed_Dec_17_15:15:52_2014
    THEBRAIN Primary Connected Peer Nearsync 344 Wed_Dec_17_15:18:22_2014
    AM Primary Connected Peer Nearsync 54 Wed_Dec_17_15:08:39_2014
    BWPRCSDB Primary Connected Peer Nearsync 15 Wed_Dec_17_15:11:11_2014


    and with lssam output
    ....
    BWPRCSDB Primary Connected Peer Nearsync 15 Wed_Dec_17_15:11:11_2014
    '- Online IBM.Application:db2_db2inst1_db2inst1_BWPRCSDB-rs
    |- Offline IBM.Application:db2_db2inst1_db2inst1_BWPRCSDB-rslx00005
    '- Online IBM.Application:db2_db2inst1_db2inst1_BWPRCSDB-rslx00006
    .....
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •