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.

2
  • 1
    See BashFAQ #6 Commented Apr 13, 2017 at 20:22
  • 2
    ...also, as an aside -- Don't Read Lines With for. See BashFAQ #1 for a discussion of best practices for working with file I/O. Consider also running your code through shellcheck.net and fixing the quoting bugs that finds. Commented Apr 13, 2017 at 20:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.