Posts

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 ...

Standby redo log add

********* #!/bin/bash # Function to run SQL*Plus commands run_sql() {     sqlplus -s / as sysdba <<EOF     SET HEADING OFF FEEDBACK OFF VERIFY OFF ECHO OFF     $1     EXIT EOF } # Get the max group, max thread, and max size from the v$log and v$logfile views redo_info=$(run_sql "SELECT MAX(l.group#), MAX(l.thread#), MAX(l.bytes/1024/1024)  FROM v\$log l, v\$logfile f  WHERE f.group# = l.group#;") # Extract the max group, max thread, and max size values max_group=$(echo "$redo_info" | awk '{print $1}') max_thread=$(echo "$redo_info" | awk '{print $2}') max_size=$(echo "$redo_info" | awk '{print $3}') # Get the number of redo groups per thread groups_per_thread=$(run_sql "SELECT COUNT(DISTINCT group#) FROM v\$log WHERE thread#=1;") # Get the recovery file destination reco_dest=$(run_sql "SHOW PARAMETER db_recovery_file_dest") reco_dest=$(echo "$reco_dest" | awk 'NR==2 {print $3}' |...

Oracle 19c Data guard

# standby_config.cfg # Database and host details PRIMARY_DB_NAME=chicago PRIMARY_DB_UNIQUE_NAME=chicago PRIMARY_HOST=primary_host PRIMARY_LOG_PATH=/u01/app/oracle/databases/chicago/redo PRIMARY_ARCHIVE_PATH=/u01/app/oracle/databases/chicago/arch STANDBY_DB_NAME=boston STANDBY_DB_UNIQUE_NAME=boston STANDBY_HOST=standby_host STANDBY_LOG_PATH=/u01/app/oracle/databases/boston/redo STANDBY_ARCHIVE_PATH=/u01/app/oracle/databases/boston/arch # Oracle Home paths ORACLE_HOME=/u01/app/oracle/product/19c/dbhome_1 ORACLE_SID=$STANDBY_DB_UNIQUE_NAME # Network and TNS details PRIMARY_TNS_ENTRY=chicago STANDBY_TNS_ENTRY=boston TNS_ADMIN=/u01/app/oracle/network/admin # ASM storage locations DATA_DISK_GROUP=+DATA RECO_DISK_GROUP=+RECO Sample 1 #!/bin/bash # Load configuration file source standby_config.cfg # Function to log messages log() {   echo "$(date +%Y-%m-%dT%H:%M:%S) - $1" } # Step 1: Prepare the primary database log "Preparing primary database..." # Check if the database is...

Demo OEM module

 #!/bin/bash # Set environment variables DB_USER="user" DB_PASS="password" DB_CONN="your_db" SQLPLUS="sqlplus -S $DB_USER/$DB_PASS@$DB_CONN" TEMP_FILE="/tmp/hosts_support_groups.txt" # Step 1: Fetch distinct host and support group for updating 'orcl_gtp_contact' SQL_QUERY_SUPPORT_GROUP="SELECT DISTINCT SUBSTR(name, INSTR(name, '@') + 1) AS host_name, support_group FROM OEM_ADMIN.CMDB_DB_CI_DAILY;" # Execute SQL query for support group and store in a file $SQLPLUS <<EOF > $TEMP_FILE $SQL_QUERY_SUPPORT_GROUP EOF # Step 2: Process Support Group from the file and generate EMCLI commands while IFS=" " read -r host_name support_group; do   # Skip header or empty lines   if [[ "$host_name" == "HOST_NAME" || -z "$host_name" ]]; then     continue   fi   # Fetch associated target types (oracle_database, rac_database, host, agent, listener) for the host   SQL_TARGETS="...

OEM target property update 5

 #!/bin/bash ########################################## # Part 1: Fetch Missing/Incorrect Properties ########################################## # Define SQL query to fetch missing/incorrect properties SQL_QUERY_MISSING=" SELECT    h.target_name,   tp.property_name,   tp.property_value,   cd.support_group,   cd.install_status,   cd.oracle_home,   cd.u_cmdb_ci_used_for,   cd.u_cmdb_owner_group,   cd.name,   cd.correlation_id,   cd.version FROM    sysman.mgmt\$target h   LEFT JOIN mgmt\$target_properties tp      ON h.target_name = tp.target_name     AND tp.property_name IN ('udtp_2', 'orcl_gtp_contact', 'orcl_gtp_lifecycle_status')   LEFT JOIN cmDAILY cd      ON h.target_name = cd.name WHERE    (tp.property_value IS NULL OR tp.property_name IS NULL)   OR (tp.property_name = 'orcl_gtp_contact' AND tp.property_value != cd.support_group)   OR (tp.pro...

OEM target property update 4

 #!/bin/bash ########################################## # Part 1: Fetch Missing/Incorrect Properties ########################################## # Define SQL query to fetch missing/incorrect properties SQL_QUERY_MISSING=" SELECT    h.target_name,   tp.property_name,   tp.property_value,   cd.support_group,   cd.install_status,   cd.oracle_home,   cd.u_cmdb_ci_used_for,   cd.u_cmdb_owner_group,   cd.name,   cd.correlation_id,   cd.version FROM    sysman.mgmt\$target h   LEFT JOIN mgmt\$target_properties tp      ON h.target_name = tp.target_name     AND tp.property_name IN ('udtp_2', 'orcl_gtp_contact', 'orcl_gtp_lifecycle_status')   LEFT JOIN cmDAILY cd      ON h.target_name = cd.name WHERE    (tp.property_value IS NULL OR tp.property_name IS NULL)   OR (tp.property_name = 'orcl_gtp_contact' AND tp.property_value != cd.support_group)   OR (tp.pro...

OEM target property update 3

 #!/bin/bash # Define SQL query to fetch host and support group from CMDB SQL_QUERY="SELECT DISTINCT SUBSTR(name, INSTR(name, '@') + 1) AS host_name, support_group             FROM OEM_ADMIN.CMDCDAILY;" # Execute SQL and store results in a temporary file sqlplus -S user/password@your_db <<EOF > /tmp/hosts_support_groups.txt $SQL_QUERY EOF # Loop through each host and support group from the query result while IFS=" " read -r host_name support_group; do   # Skip header or empty lines   if [[ "$host_name" == "HOST_NAME" || -z "$host_name" ]]; then     continue   fi      # SQL query to fetch associated target types (oracle_database, rac_database, host, agent, listener) for the host   SQL_TARGETS="SELECT assoc_target_name, target_type                 FROM sysman.mgmt\$target_associations                 WHERE a...