Database version list for patching

# Remove all existing log files

rm -f db_version_*.txt


# Loop through each database

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

    export ORACLE_SID=$SID

    source oraenv <<< "$SID"


    # Execute SQL query to get the version

    version=$(sqlplus -S / as sysdba <<EOF

    set heading off

    set feedback off

    SELECT i.version FROM v\$instance i;

    EXIT;

EOF

)


    # Sanitize the version string for use in a file name

    sanitized_version=$(echo "$version" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')


    # Create a new log file for each database

    output_file="db_version_${sanitized_version}.txt"


    # Capture the database name using sqlplus command

    database_name=$(sqlplus -S / as sysdba <<EOF

    set heading off

    set feedback off

    SELECT d.name FROM v\$database d;

    EXIT;

EOF

)


    # Echo the database name to the log file, excluding empty lines

    echo "Database Name: $database_name" | grep -v '^$' >> "$output_file"


done

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add