cat dblist.sh
#!/bin/sh
rm -rf DB_Stat.log sp_db_status.log
status_db () {
DB=`ps -ef |grep pmon |egrep -v "grep|ASM|CDB|MGMTDB" |awk '{print $8}'|cut -d '_' -f3`
#DB=`cat $LOG_DIR/before_patch.log`
for i in `echo $DB`
do
#sleep 1
export ORACLE_SID=$i
export ORAENV_ASK=NO
echo "connecting to the databbase $i"
. oraenv $i
#sqlplus -s "/ as sysdba" <
stat_db=`sqlplus -s "/ as sysdba" <
set pages 5
col inst_id for 99
col instance_name for a10
col name for a10
col open_mode for a25
col i.logins for a14
set feedback off hea off time off timing off
spool sp_db_status.log append
select i.instance_name,d.name ,d.open_mode, i.logins from v\\$instance i, v\\$database d order by 1 ;
spool off;
exit;
EOF`
#echo "$stat" | tee -a CDB_Stat.log
#echo "INSTANCE_N NAME OPEN_MODE LOGINS" >> DB_Stat.log
#echo "---------- ---------- -------------- ----------" >> DB_Stat.log
echo "$stat_db" >> DB_Stat.log
#cat DB_Stat.log -n > DB_Stat.log
done
export i=
export DB=
}
status_cdb () {
CDB=`ps -ef |grep pmon |egrep CDB |awk '{print $8}'|cut -d '_' -f3`
#DB=`cat $LOG_DIR/before_patch.log`
for i in `echo $CDB`
do
#sleep 1
export ORACLE_SID=$i
export ORAENV_ASK=NO
echo "connecting to the databbase $i"
. oraenv $i
#sqlplus -s "/ as sysdba" <
stat_cdb=`sqlplus -s "/ as sysdba" <
set pages 20
set lines 100
col status for a30
col name for a10
col open_mode for a25
col restricted for a14
set feedback off hea off time off timing off
spool sp_cdb_status.log append
select p.name ,c.name ,p.open_mode ,p.restricted from v\\$pdbs p, v\\$database c where p.name <> 'PDB\\$SEED' order by 2,1 ;
spool off;
exit;
EOF`
#echo "$stat" | tee -a CDB_Stat.log
echo "$stat_cdb" >> DB_Stat.log
cat DB_Stat.log -n >> DB_Stat.logn
done
export i=
export DB=
}
status_db
status_cdb
#rm DB_Stat.lo
#awk NF DB_Stat.logn > DB_Stat.log
#echo "" >> DB_Stat
#echo "INSTANCE_N NAME OPEN_MODE RESTRICTED" > DB_Stat
#echo "---------- ---------- -------------- ----------" >> DB_Stat
awk NF DB_Stat.log > DB_Stat
cat DB_Stat -n > DB_Statn
sed -i '1 i\ ' DB_Statn
sed -i '2 i\ INSTANCE_N NAME OPEN_MODE RESTRICTED' DB_Statn
sed -i '3 i\ ---------- ---------- ------------------------- ----------' DB_Statn
#cat DB_Stat.lo
cat DB_Statn
exit;