Note : You can use same script in Exadata also.
Changes required for Exadata.
DIR == change /home/monitoring with Shared location across all DB nodes. Eg: ZFS mount point
Schedule below command in crontab script
dcli -l oracle -g ~/dbs_group “$shared_location/ALL_PDB_CONNECT.sh”
== Script Start ==
## All_PDB_CONNECT.sh
#Script to Connect to ALL PDB amd perform similar action all PDB — Like User Creation,Parameter check etc
# set the Oracle environement to be able to run in crontab
DIR=/home/monitoring/ALL_PDB
PATH=$PATH:/usr/local/bin
date=`date`
PDB_LOG=$DIR/log/All_PDB_`hostname`.log
if [ -f $PDB_LOG ] ;
then
rm $PDB_LOG
fi
ps -eaf | grep ora_smon|grep -v grep |tr -s ” ” | cut -d ” ” -f8 | cut -d _ -f3|grep ‘[1]$’ > $DIR/config/instance_name_`hostname`
cat $DIR/config/instance_name_`hostname` | while read INSTANCE
do
export ORACLE_SID=$INSTANCE
export ORAENV_ASK=NO
. /usr/local/bin/oraenv > /dev/null
(sqlplus -s -l / as sysdba << EOF
set head off
set echo off
set feedback off
select NAME from v\$pdbs where NAME!=’PDB\$SEED’;
exit
EOF
) > $DIR/config/pdb/PDB_$ORACLE_SID.log
done
ps -eaf | grep ora_smon|grep -v grep |tr -s ” ” | cut -d ” ” -f8 | cut -d _ -f3|grep ‘[1]$’ > $DIR/config/instance_name_`hostname`
cat $DIR/config/instance_name_`hostname` | while read INSTANCE
do
export ORACLE_SID=$INSTANCE
export ORAENV_ASK=NO
. /usr/local/bin/oraenv > /dev/null
cat $DIR/config/pdb/PDB_$ORACLE_SID.log | grep -v ^$| while read PDB
do
$DIR/pdb_run.sh $PDB >> $DIR/log/All_PDB_`hostname`.log
done
done
if [ -f $PDB_LOG ] ;
then
cat $DIR/log/All_PDB_`hostname`.log
exit 1
fi
== Script End ==
====================
# Sub Script — pdb_run.sh —
sqlplus -s -l / as sysdba <<EOF
set head off
set echo off
set feedback off
alter session set container=$1;
show con_name
–Any SQL command
select name from v\$database;
Create User test identified by Welcome1;
select name,open_mode from gv\$pdbs;
–Any SQL command
EXIT;
EOF
=======================