GoldenGate Process Monitor

ADVERTISEMENT

Automated Monitoring of Oracle GoldenGate Processes Using Shell Script

This shell script is part of a broader Shell Script Automation toolkit designed for Oracle DBAs. It automatically monitors key Oracle GoldenGate processes — including Manager, Extract, Replicat, and JAgent — and sends alerts if any of them stop or abend. With embedded configuration and optional fallback auto-detection, the script is highly portable across environments. It’s ideal for proactive replication health monitoring via cron scheduling.

📄 Shell Script: gg_alert.sh

#!/bin/bash

################################################################################
# Title   : Automated Monitoring of Oracle GoldenGate Processes Using Shell Script
# Script  : gg_alert.sh
# Purpose : Monitors GoldenGate processes (Manager, Extract, Replicat, JAgent)
#           and sends alerts via email if any are STOPPED or ABENDED.
#
# Features:
#   - Self-contained script (no external config)
#   - Fallback auto-detection for GG_HOME and ORACLE_HOME
#   - Sends email alerts with report file
#   - Cron-friendly and easily portable across environments
#
# Author  : W3Buddy
# Version : 1.0
################################################################################

### --- Configuration Section --- ###
GG_HOME="/goldengate/install/software/gghome_1"
ORACLE_HOME="/oracle/app/oracle/product/12.1.0/db_1"
EMAIL_LIST="info.w3buddy@gmail.com"
#####################################

# --- Fallback auto-detection if not set ---
GG_HOME=${GG_HOME:-$(dirname "$(command -v ggsci 2>/dev/null)")}
ORACLE_HOME=${ORACLE_HOME:-"/oracle/app/oracle/product/12.1.0/db_1"}
EMAIL_LIST=${EMAIL_LIST:-"dba@example.com"}

# --- Environment Setup ---
export GG_HOME
export ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

# Save and set IFS
OIFS=$IFS
IFS=$'\n'

# --- Fetch GoldenGate process status ---
function fetch_status {
    OUTPUT=$("$GG_HOME"/ggsci <<EOF
info all
exit
EOF
)
}

# --- Send alerts for STOPPED or ABENDED processes ---
function send_alerts {
    for line in $OUTPUT; do
        if echo "$line" | grep -E 'MANAGER|EXTRACT|REPLICAT|JAGENT' >/dev/null; then
            GTYPE=$(echo "$line" | awk '{print $1}')
            GSTAT=$(echo "$line" | awk '{print $2}')
            GNAME=$(echo "$line" | awk '{print $3}')
            SUBJECT=""
            REPORT_FILE=""

            # Alert for MANAGER and JAGENT if not RUNNING
            if [[ "$GTYPE" == "MANAGER" || "$GTYPE" == "JAGENT" ]]; then
                if [[ "$GSTAT" != "RUNNING" ]]; then
                    SUBJECT="${HOSTNAME} - GoldenGate ${GTYPE} ${GSTAT}"
                    REPORT_FILE="$GG_HOME/dirrpt/${GTYPE}.rpt"
                fi
            fi

            # Alert for EXTRACT or REPLICAT if STOPPED or ABENDED
            if [[ "$GTYPE" == "EXTRACT" || "$GTYPE" == "REPLICAT" ]]; then
                if [[ "$GSTAT" == "STOP" || "$GSTAT" == "ABEND" ]]; then
                    SUBJECT="${HOSTNAME} - GoldenGate ${GTYPE} ${GNAME} ${GSTAT}"
                    REPORT_FILE="$GG_HOME/dirrpt/${GNAME}.rpt"
                fi
            fi

            # Send email if subject and report file exist
            if [[ -n "$SUBJECT" && -f "$REPORT_FILE" ]]; then
                mailx -s "$SUBJECT" "$EMAIL_LIST" < "$REPORT_FILE"
            fi
        fi
    done
}

# Run monitoring logic
fetch_status
send_alerts

# Restore IFS
IFS=$OIFS

⚙️ Setup Instructions

# ----------------------------------------------
# 1. Create the script file on GoldenGate server
# ----------------------------------------------
cd /home/goldengate

# Create the script file
vi gg_alert.sh

# (Paste the full gg_alert.sh script content inside and save)

# ----------------------------------------------
# 2. Make the script executable
# ----------------------------------------------
chmod +x gg_alert.sh

# ----------------------------------------------
# 3. Verify mailx is installed for email alerts
# ----------------------------------------------
which mailx

# If not found, install it:
# RHEL/CentOS:
sudo yum install mailx

# Ubuntu/Debian:
sudo apt install mailutils

# ----------------------------------------------
# 4. Test the script manually
# ----------------------------------------------
./gg_alert.sh

# Ensure it captures GoldenGate status and sends alerts if any process is down.

# ----------------------------------------------
# 5. Schedule via cron to run every 30 minutes
# ----------------------------------------------
crontab -e

# Add this entry:
00,30 * * * * /home/goldengate/gg_alert.sh >> /home/goldengate/gg_alerts.log 2>&1

# ----------------------------------------------
# 6. Confirm cron is scheduled
# ----------------------------------------------
crontab -l

Summary

This script provides a lightweight, fully automated solution for monitoring GoldenGate components without requiring manual checks. It ensures DBAs are notified proactively when something goes wrong — reducing replication downtime and improving operational reliability.

ADVERTISEMENT