Friday 15 May 2015

Running script on all database

If we have multiple instances running on one servers and some script we need to run on all db's, then its good we use below script to set ORACLE_SID and login and run the script.

This specially used for below scenario:
  1. DB level patching in one go.
  2. While patching take snap of before and after patch.
  3. Some DB level script for reporting.



for i in `ps -aef | grep pmon |awk '{print $8}' |  egrep -i -v 'grep|asm' | cut -d "_" -f3`
do
  echo "ORACLE_SID $i : `hostname`"
  export ORACLE_SID=$i
  sqlplus -s / as sysdba <<EOF
  set lin 180
  select instance_name,host_name from v\$instance;
  srvctl status database -d $i
  exit
EOF
done


awk index = oracle instr

[oracle@node1 ~]$ cat /etc/oratab | egrep node | grep -v '#B' | awk -F ':' '{print substr($1,1,index($1,"1")-1)}'
node
[oracle@node1 ~]$

Filter blank lines


cat /etc/oratab | grep -v '^$'

No comments:

Post a Comment