Oracle 环境变量获取
for SID in `ps -ef | grep pmon | grep -v grep | grep -v ASM | cut -d"_" -f3,4 `
do
#export ORACLE_BASE=/u01/app/grid
#export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_2
#export ORACLE_SID=noexist
#export LD_LIBRARY_PATH=$ORACLE_HOME/lib
#export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
export ORACLE_SID=$SID
export ORAENV_ASK=NO
. oraenv
echo Database instance checking is : $SID
echo " <(----------Blank Represents DB Run perfect----------)>"
value=`sqlplus -s / as sysdba < set pagesize 0 feedback off verify off heading off echo off numwidth 9 ;
select count(*) from gv\\\$database a where a.OPEN_MODE in ('READ WRITE') and rownum<2;
exit;
EOF`
if [ $value == 1 ];
then
echo "THIS IS PRIMARY DATABASE"
sqlplus -s ' / as sysdba' <
"SunOS" ) ORATAB=/var/opt/oracle/oratab
TNS_ADMIN=/var/opt/oracle
ORA_ORAENV=/opt/bin/ora_oraenv
"HP-UX" ) ORATAB=/etc/oratab
ORA_ORAENV=/usr/local/bin/ora_oraenv
ORA_ORAENV=/usr/local/bin/ora_oraenv
export TNS_ADMIN ORA_ORAENV
SIDLIST=`awk -F: '/^[^#]/{printf "\n %s",$1}' ${ORATAB}`
case "${ORAENV_ASK:-''}" in
echo "SIDs on this machine are; ${SIDLIST}
if [ -d ${ORACLE_HOME} ]; then
ORACLE_BASE=`cd ${ORACLE_HOME}/../..; pwd`
echo "Warning - Oracle HOME not valid, Oracle BASE not set correctly"
LOCAL=${ORACLE_BASE}/local
DB=${ORACLE_BASE}/admin/${ORACLE_SID}
ORACLE_PATH=${DB}/adhoc:${LOCAL}:.
export DBA DB LOCAL ORACLE_PATH
*: ) PATH=${PATH}${LOCAL}:
* ) PATH=${PATH}:${LOCAL}:
Oracle SID = ${ORACLE_SID}
Oracle BASE = ${ORACLE_BASE}
Oracle HOME = ${ORACLE_HOME}
SQL*Net TNS = ${TNS_ADMIN}