#!/bin/bash
# Define the path to oratab
ORATAB="/etc/oratab"
# Check if oratab exists
if [ ! -f $ORATAB ]; then
echo "$ORATAB not found. Exiting."
exit 1
fi
DB_STATUS_FILE="/tmp/db_status.log"
GGSCI_PATH="/usr/local/bin/ggsci" # Modify this to your GoldenGate installation path
LAG_THRESHOLD=0 # Set your lag threshold in seconds (0 for no lag allowed)
# Arrays to hold summary information
DB_HEALTH_GREEN=()
DB_NOT_OK=()
WALLET_COUNT=0
WALLET_DB_LIST=()
GOLDENGATE_FOUND="No"
TOTAL_DATABASES_SCANNED=0
# Function to set Oracle environment for a specific database
set_oracle_env() {
DB_NAME=$1
ORACLE_HOME=$2
export ORACLE_HOME=$ORACLE_HOME
export ORACLE_SID=$DB_NAME
export PATH=$ORACLE_HOME/bin:$PATH
echo "Set environment for database: $DB_NAME with ORACLE_HOME: $ORACLE_HOME"
}
# Function to check if a database is up and running
check_db_status() {
DB_NAME=$1
echo "Checking status for database: $DB_NAME..."
ps -ef | grep pmon | grep $DB_NAME | grep -v grep > $DB_STATUS_FILE
if [ -s $DB_STATUS_FILE ]; then
echo "Database $DB_NAME is up and running."
return 0
else
echo "Database $DB_NAME is down."
DB_NOT_OK+=("$DB_NAME is down: NOT_OK")
return 1
fi
}
# Other functions remain the same...
# Function to re-scan based on pmon instances
re_run_scan() {
echo "Re-scanning based on running pmon instances..."
for DB_NAME in $pmon_processes; do
# Get ORACLE_HOME for the running instance from oratab
ORACLE_HOME=$(grep "^$DB_NAME:" $ORATAB | cut -d: -f2)
if [ -z "$ORACLE_HOME" ]; then
echo "ORACLE_HOME not found for $DB_NAME. Skipping."
continue
fi
# Increment the total databases scanned again for pmon instances
TOTAL_DATABASES_SCANNED=$((TOTAL_DATABASES_SCANNED + 1))
# Set the Oracle environment for each database
set_oracle_env "$DB_NAME" "$ORACLE_HOME"
# Run checks for each database
check_db_status "$DB_NAME"
# Only perform Data Guard checks if the database is up
if [ $? -eq 0 ]; then
check_dgmgrl_lag "$DB_NAME"
fi
# Always perform the mode check
check_db_mode "$DB_NAME"
echo "-------------------------------------------"
done
}
# Read oratab and loop through each database
while IFS=: read -r DB_NAME ORACLE_HOME DB_STARTUP_FLAG; do
# Skip comments and entries with no ORACLE_HOME
if [[ "$DB_NAME" =~ ^# ]] || [ -z "$ORACLE_HOME" ] || [[ "$DB_NAME" == "oracon_1" ]]; then
continue
fi
TOTAL_DATABASES_SCANNED=$((TOTAL_DATABASES_SCANNED + 1))
# Set the Oracle environment for each database
set_oracle_env "$DB_NAME" "$ORACLE_HOME"
# Run checks for each database
check_db_status "$DB_NAME"
# Only perform Data Guard checks if the database is up
if [ $? -eq 0 ]; then
check_dgmgrl_lag "$DB_NAME"
fi
# Always perform the mode check
check_db_mode "$DB_NAME"
echo "-------------------------------------------"
done < $ORATAB
# Run wallet identifier check
check_wallet_identifiers
# Run Goldengate check
check_goldengate
# Print summary of wallet identifiers
echo "================== SUMMARY =================="
# Check wallet count and output result
if [ "$WALLET_COUNT" -gt 0 ]; then
echo "Action required: $WALLET_COUNT databases found with wallet configured."
echo "Databases with wallets:"
for wallet_db in "${WALLET_DB_LIST[@]}"; do
echo "$wallet_db"
done
else
echo "No wallet-configured databases found."
fi
# Check for Goldengate and report in summary
if [ "$GOLDENGATE_FOUND" == "Yes" ]; then
echo "Goldengate executable found. Please double-check and perform GG healthcheck manually."
fi
# Print databases that have any issues (NOT_OK)
echo "================== ATTENTION =================="
if [ ${#DB_NOT_OK[@]} -eq 0 ]; then
echo "No databases have issues."
else
echo "Databases with issues:"
for db in "${DB_NOT_OK[@]}"; do
echo "$db"
done
fi
# Print databases that passed all checks (excluding those marked as NOT_OK)
echo "================== HEALTH CHECK =================="
if [ ${#DB_HEALTH_GREEN[@]} -eq 0 ]; then
echo "No databases passed the health check."
else
for db in "${DB_HEALTH_GREEN[@]}"; do
echo "$db"
done
fi
# New section for total number of running databases and instances based on pmon processes
echo "================== PMON CHECK =================="
# Check total number of running databases by checking pmon
pmon_processes=$(ps -ef | grep pmon | grep -v grep | awk '{print $NF}' | cut -d'_' -f3 | sort -u)
TOTAL_PMOS_FOUND=$(echo "$pmon_processes" | wc -l)
echo "Total number of databases scanned: $TOTAL_DATABASES_SCANNED"
echo "Total number of instances running as per PMON processes: $TOTAL_PMOS_FOUND"
# Prompt to re-run the scan based on running pmon instances
echo "Do you want to re-run the scan based on running PMON instances? (Y/N)"
read -r re_run_choice
if [[ "$re_run_choice" =~ ^[Yy]$ ]]; then
re_run_scan
fi
echo "============================================="





0 comments:
Post a Comment