#!/bin/bash # File path for output OUTPUT_FILE="/tmp/db_version_info.tmp" PDB_LIST_FILE="/tmp/pdb_list.tmp" > "$OUTPUT_FILE" # Clear the output file before starting touch $OUTPUT_FILE chown oracle $OUTPUT_FILE # Function to get the Oracle Database version get_oracle_version() { su - oracle -s /bin/bash -c " sqlplus -s / as sysdba <<'EOF' >> \"$OUTPUT_FILE\" whenever sqlerror exit sql.sqlcode; SET ECHO ON SET HEADING ON SET UNDERLINE '=' SET FEEDBACK OFF SET LINESIZE 150 SET PAGESIZE 100 COLUMN BANNER FORMAT A80 PROMPT Oracle Database Version:; SELECT banner FROM v\$version WHERE banner LIKE 'Oracle%' AND ROWNUM = 1; exit; EOF " } # Function to get APEX and ORDS versions within a specific container get_apex_ords_versions() { local container_name="$1" su - oracle -s /bin/bash -c " sqlplus -s / as sysdba <> \"$OUTPUT_FILE\" whenever sqlerror exit sql.sqlcode; set echo off set heading on SET UNDERLINE '=' set feedback off set linesize 150 -- Switch to the specified container ALTER SESSION SET CONTAINER = $container_name; -- Print the container name for clarity PROMPT Version information for container: $container_name; -- APEX version PROMPT APEX Version:; SELECT version_no AS version FROM apex_release; -- ORDS version PROMPT ORDS Version:; SELECT 'ORDS is ' || version AS \"Version of ORDS\" FROM ords_metadata.ords_schema_version; exit; EOF " } # Run the Oracle version query echo "Gathering Oracle Database version..." >> "$OUTPUT_FILE" get_oracle_version # Get a list of all PDBs, excluding PDB$SEED, and write to a temporary file su - oracle -s /bin/bash -c " sqlplus -s / as sysdba <<'EOF' set heading off set feedback off set pagesize 0 spool $PDB_LIST_FILE SELECT NAME FROM v\$pdbs WHERE NAME NOT IN ('PDB\$SEED'); spool off exit; EOF " # Verify that the PDB_LIST_FILE was created and contains data if [[ -f "$PDB_LIST_FILE" && -s "$PDB_LIST_FILE" ]]; then # Read each valid PDB name from the temporary file while IFS= read -r PDB; do PDB=$(echo "$PDB" | xargs) # Trim any leading/trailing whitespace if [[ -n "$PDB" ]]; then echo "Gathering APEX and ORDS versions for PDB: $PDB..." >> "$OUTPUT_FILE" get_apex_ords_versions "$PDB" fi done < "$PDB_LIST_FILE" else echo "No PDBs found or could not access v\$pdbs view" >> "$OUTPUT_FILE" fi cat "$OUTPUT_FILE" # Clean up the temporary file rm -f "$PDB_LIST_FILE"