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 <<EOF
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' <<EOF
oraenv的设置
ORAENV便于设置oracle环境存储路径:$ORACLE_HOME/binORAENV_ASK:设置是否需要交互复制代码
交互式:$ . oraenv
ORACLE_SID = [] ? orcl非交互式
$ export ORACLE_SID=orcl
$ export ORAENV_ASK=NO
$ . oraenv
复制代码
代码,网上找的:复制代码
#!/bin/sh
#
# Get the machine type and then set up ORATAB and TNS_ADMIN variables
#
MACH_TYPE=`uname -s`
case ${MACH_TYPE} in"SunOS" ) ORATAB=/var/opt/oracle/oratabTNS_ADMIN=/var/opt/oracleORA_ORAENV=/opt/bin/ora_oraenv;;"HP-UX" ) ORATAB=/etc/oratabTNS_ADMIN=/etcORA_ORAENV=/usr/local/bin/ora_oraenv;;* ) ORATAB=/etc/oratabTNS_ADMIN=/etcORA_ORAENV=/usr/local/bin/ora_oraenv;;
esacexport TNS_ADMIN ORA_ORAENV
#
# Extract a list of Oracle SID's that are defined with the oratab file
#
SIDLIST=`awk -F: '/^[^#]/{printf "\n %s",$1}' ${ORATAB}`
case "${ORAENV_ASK:-''}" inNO ) ;;* ) clearecho "SIDs on this machine are; ${SIDLIST}
";;
esac
#
# This is the official oraenv file as supplied by Oracle
#
. ${ORA_ORAENV}if [ -d ${ORACLE_HOME} ]; thenORACLE_BASE=`cd ${ORACLE_HOME}/../..; pwd`
elseORACLE_BASE=${HOME}echoecho "Warning - Oracle HOME not valid, Oracle BASE not set correctly"
fi
export ORACLE_BASELOCAL=${ORACLE_BASE}/local
DBA=${ORACLE_BASE}/admin
DB=${ORACLE_BASE}/admin/${ORACLE_SID}
ORACLE_PATH=${DB}/adhoc:${LOCAL}:.
export DBA DB LOCAL ORACLE_PATHcase ${PATH} in*${LOCAL}* ) ;;*: ) PATH=${PATH}${LOCAL}:;;* ) PATH=${PATH}:${LOCAL}:;;
esac
export PATHecho "
Oracle SID = ${ORACLE_SID}
Oracle BASE = ${ORACLE_BASE}
Oracle HOME = ${ORACLE_HOME}
SQL*Net TNS = ${TNS_ADMIN}
"