0

I have pdb_lists.log as follows:

cat pdb_lists.log
'PDB1','PDB2' 

I need to check TDE status of each PDB from above list and assign to new variable

 for i in $( cat $SQL_SPOOL_LOG_DIR/pdb_lists.log | sed "s/,/ /g" | sed "s/'/ /g")
        do
 PDB_TE_STATUS=$ORACLE_HOME/bin/sqlplus '/as sysdba' << EOF 
            whenever sqlerror exit failure
            connect / as sysdba
            set head off
            set pagesize 0
            set linesize 145
            set feedback off
            alter session set container=$i;
    show con_name;
            spool $SQL_SPOOL_LOG_DIR/pdb_te_enable_status.log
            select status from v\encryption_wallet;
            spool off
 EOF
 CDB_CREATOR_PDB=$ORACLE_HOME/bin/sqlplus '/as sysdba' << EOF 
            whenever sqlerror exit failure
            connect / as sysdba
            set head off
            set pagesize 0
            set linesize 145
            set feedback off
            alter session set container=$i;
    show con_name;
            spool $SQL_SPOOL_LOG_DIR/pdb_cdb_creator_pdb_status.log
            select distinct CREATOR_PDBNAME from v\$encryption_keys where CREATOR_PDBNAME not like 'CDB$ROOT%' and KEY_ID is not null;
            spool off
  EOF
  done

Once I have a new variable assigned for each PDB, then I need run based on the value to respective sql.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • 1
    See [BashFAQ #6](http://mywiki.wooledge.org/BashFAQ/006) – Charles Duffy Apr 13 '17 at 20:22
  • 2
    ...also, as an aside -- [Don't Read Lines With `for`](http://mywiki.wooledge.org/DontReadLinesWithFor). See [BashFAQ #1](http://mywiki.wooledge.org/BashFAQ/001) for a discussion of best practices for working with file I/O. Consider also running your code through http://shellcheck.net/ and fixing the quoting bugs that finds. – Charles Duffy Apr 13 '17 at 20:22

1 Answers1

1

Use an associative array. Associative arrays (also known as maps or dictionaries) behave like arrays, but allow arbitrary strings as indices.

declare -A status
for pdb in ...; do
   status["$pdb"]=...
done

To read the status of a PDB (whatever that is), use ${status[nameOfThePDB]}.

Socowi
  • 25,550
  • 3
  • 32
  • 54