Oracle環境變量設置腳本

每次都傻乎乎的往bashrc裏面寫環境變量,感受不任性。因而,看了本書瞭解了/etc/oratab這個東東後,參考着書也寫了一個設置Oracle環境變量的腳本。bash

在/etc/下建立oraset,權限設置爲chown oracle:oinstall /etc/orasetoracle

oraset內容:spa

#!/bin/bash
# Sets Oracle environment variables.
# Setup: 1. Put oraset file in /etc(Linux), in /var/opt/oracle(Solaris)
#        2. Ensure /etc or /var/opt/oracle is in $PATH
# Usage: batch mode: . oraset <SID>
#        menu mode: . oraset
#=======================================================
if [ -f /etc/oratab ]; then
    OTAB=/etc/oratab
elif [ -f /var/opt/oracle/oratab ]; then
    OTAB=/var/opt/oracle/oratab
else
    echo 'oratab file not found.'
    exit
fi
#
if [ -z $1 ]; then
    SIDLIST=$(egrep -v '#|\*' ${OTAB} | cut -f1 -d:)
    # PS3 inmdicates the prompt to be used for the Bash select command.
    PS3='SID?'
    select sid in ${SIDLIST}; do
        if [ -n $sid ]; then
            HOLD_SID=$sid
            break;
        fi
    done
else
    if egrep -v '#|\*' ${OTAB} | grep -w "${1}:">/dev/null; then
        HOLD_SID=$1
    else
        echo "SID: $1 not found in $OTAB"
    fi
    shift
fi
#
ORACLE_SID=$HOLD_SID
export ORACLE_SID
export ORACLE_HOME=$(egrep -v '#|\*' ${OTAB} | grep -w $ORACLE_SID:|cut -f2 -d:)
export ORACLE_BASE=${ORACLE_HOME%%/product*}
export TMP=$ORACLE_BASE/../tmp
export TMPDIR=$TMP
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ADR_BASE=$ORACLE_BASE/diag
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib

而後在oracle用戶的.bashrc裏面添加:插件

source /etc/oraset xxxxcode

注:blog

1. xxxx爲你SID的名稱。it

2. 路徑以我的安裝爲準。class

3. 誰知道怎麼在Live Writer的代碼亮度插件裏添加行號和奇偶行不一樣色?變量

 

附:sed

系統:Red Hat Enterprise Linux7.0

Oracle:12c Enterprise

 

轉載請註明出處····································

相關文章
相關標籤/搜索