tnsping and db check

 #!/bin/bash


# Function to run SQL*Plus commands

run_sql() {

    OUTPUT=$(sqlplus -s /nolog <<EOF

SET HEADING OFF FEEDBACK OFF VERIFY OFF ECHO OFF

$1

EXIT

EOF

    )

    echo "$OUTPUT" | grep "Connected to:"

}


# Function to log messages

log() {

    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"

}


password="xxxx"


# Step: sqlplus /nolog

if run_sql "connect sys/$password@boston AS SYSDBA"; then

    log "Connection to Boston successful."

else

    log "Connection to Boston failed."

fi


if run_sql "connect sys/$password@chicago AS SYSDBA"; then

    log "Connection to Chicago successful."

else

    log "Connection to Chicago failed."

fi


# Step: Check SQL*Net connectivity

log "Checking SQL*Net connectivity..."


# Replace with your TNS entry names

PRIMARY_TNS_ENTRY="boston"

STANDBY_TNS_ENTRY="chicago"


# Check primary connectivity

if tnsping $PRIMARY_TNS_ENTRY > /dev/null 2>&1; then

    log "TNSPing to $PRIMARY_TNS_ENTRY successful."

else

    log "TNSPing to $PRIMARY_TNS_ENTRY failed."

fi


# Check standby connectivity

if tnsping $STANDBY_TNS_ENTRY > /dev/null 2>&1; then

    log "TNSPing to $STANDBY_TNS_ENTRY successful."

else


    log "TNSPing to $STANDBY_TNS_ENTRY failed."

fi

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add