Oratab Entries validate and add

#!/bin/bash


# Ask user for log directory

read -p "Enter the log directory: " log_directory

log_directory=$(realpath "$log_directory")


# Ask user for file2 (sop.conf) name

read -p "Enter the name of sop.conf file: " file2_name

file2_path="$log_directory/$file2_name"


# Phase 1: Generate db_unique_name_version.log

for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do

    export ORACLE_SID=$SID

    source oraenv <<< "$SID"


    # Get DB unique name and version using the first query

    DB_UNIQUE_NAME_INFO=$(sqlplus -s / as sysdba <<EOF

set feedback off

set heading off

SELECT d.DB_UNIQUE_NAME || ':' || SUBSTR(i.VERSION, 1, 2) FROM v\$database d, v\$instance i;

EOF

    )


    # Get instance name and version using the second query

    INSTANCE_NAME_INFO=$(sqlplus -s / as sysdba <<EOF

set feedback off

set heading off

SELECT i.INSTANCE_NAME || ':' || SUBSTR(i.VERSION, 1, 2) FROM v\$instance i;

EOF

    )


    # Append to db_unique_name_version.log without empty lines

    echo "$DB_UNIQUE_NAME_INFO" | sed '/^$/d' >> "$log_directory/db_unique_name_version.log"

    echo "$INSTANCE_NAME_INFO" | sed '/^$/d' >> "$log_directory/db_unique_name_version.log"

done


# Phase 2: Read data from db_unique_name_version.log and file2, and print in file3

while IFS=':' read -r db_name version; do

    # Trim leading/trailing whitespaces from version

    version=$(echo "$version" | tr -d '[:space:]')


    # Determine the Oracle home based on the version

    case "$version" in

        "19")

            ORACLE_HOME=$(grep "^19:" "$file2_path" | cut -d':' -f2 | tr -d '[:space:]')

            ;;

        "12")

            ORACLE_HOME=$(grep "^12:" "$file2_path" | cut -d':' -f2 | tr -d '[:space:]')

            ;;

        "11")

            ORACLE_HOME=$(grep "^11:" "$file2_path" | cut -d':' -f2 | tr -d '[:space:]')

            ;;

        *)

            # Handle any other versions if needed

            ORACLE_HOME=""

            ;;

    esac


    # Create entry in file3

    echo "$db_name: $ORACLE_HOME:N" >> "$log_directory/file3.log"


done < "$log_directory/db_unique_name_version.log"


echo "File3 created with entries based on database information and $file2_name in $log_directory."

Comments

Popular posts from this blog

deployment pre patch

Golden gate v1