转 oraenv

时间:2024-01-11 21:07:44

代码如下:

"oraenv"  lines,  characters
#!/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/oratab
TNS_ADMIN=/var/opt/oracle
ORA_ORAENV=/opt/bin/ora_oraenv
;;
"HP-UX" ) ORATAB=/etc/oratab
TNS_ADMIN=/etc
ORA_ORAENV=/usr/local/bin/ora_oraenv
;;
* ) ORATAB=/etc/oratab
TNS_ADMIN=/etc
ORA_ORAENV=/usr/local/bin/ora_oraenv
;;
esac export 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:-''}" in
NO ) ;;
* ) clear
echo "SIDs on this machine are; ${SIDLIST}
"
;;
esac
#
# This is the official oraenv file as supplied by Oracle
#
. ${ORA_ORAENV} if [ -d ${ORACLE_HOME} ]; then
ORACLE_BASE=`cd ${ORACLE_HOME}/../..; pwd`
else
ORACLE_BASE=${HOME}
echo
echo "Warning - Oracle HOME not valid, Oracle BASE not set correctly"
fi
export ORACLE_BASE LOCAL=${ORACLE_BASE}/local
DBA=${ORACLE_BASE}/admin
DB=${ORACLE_BASE}/admin/${ORACLE_SID}
ORACLE_PATH=${DB}/adhoc:${LOCAL}:.
export DBA DB LOCAL ORACLE_PATH case ${PATH} in
*${LOCAL}* ) ;;
*: ) PATH=${PATH}${LOCAL}:
;;
* ) PATH=${PATH}:${LOCAL}:
;;
esac
export PATH echo "
Oracle SID = ${ORACLE_SID}
Oracle BASE = ${ORACLE_BASE}
Oracle HOME = ${ORACLE_HOME}
SQL*Net TNS = ${TNS_ADMIN}
"

(1)在登录主机之后,习惯性的设置环境变量:

stty erase ^?
set -o vi
set ORAENV_ASK=YES
1
2
3
stty erase ^?
set -o vi
set ORAENV_ASK=YES
注意ORAENV_ASK这个参数和oraenv配合使用。当设置ORAENV_ASK=YES时,运行oraenv会提示当前的数据库sid:

[oracle@standby1 ~]$ export ORAENV_ASK=NO
[oracle@standby1 ~]$ oraenv
[oracle@standby1 ~]$
[oracle@standby1 ~]$
[oracle@standby1 ~]$ export ORAENV_ASK=YES
[oracle@standby1 ~]$ oraenv
ORACLE_SID = [oradg] ?
[oracle@standby1 ~]$
1
2
3
4
5
6
7
8
[oracle@standby1 ~]$ export ORAENV_ASK=NO
[oracle@standby1 ~]$ oraenv
[oracle@standby1 ~]$
[oracle@standby1 ~]$
[oracle@standby1 ~]$ export ORAENV_ASK=YES
[oracle@standby1 ~]$ oraenv
ORACLE_SID = [oradg] ?
[oracle@standby1 ~]$