aoe
#!/usr/bin/ksh
# =============================================================================
# File Name: aoe
#
# Function: Configures the oracle environment
#
# Usage: . aoe [SID] [-]
#
# Remarks: aoe is a simple front end to the oracle oraenv utility.
# If a SID is not specified at the command line, a menu will be
# displayed, listing all available entries in the oratab.
# Once a selection has been made oraenv is called and if one exists
# an optional config script will also be executed.
# The optional config script must be located in
# $optional_script_dir and be named as follows: aoe_<SID>
# If - is specified as the last parameter, aoe will
# launch sqlplus "/ as sysdba".
#
# Notes: It is worth adding the following to you .profile (or .bash_profile):
# alias aoe=". aoe"
# Doing so removes the need to prefix the command with ". "
#
# Change History:
#
# Date Ver Author Change
# ======== ==== =============== ===============================================
# 15/06/06 1.0 Andy Barry Initial version.
# 30/08/06 1.1 Andy Barry Added the option to run sqlplus "/ as sysdba"
# when "-" is specified as the last parameter.
oratab=/etc/oratab
oraenv=/usr/local/bin/oraenv
optional_script_dir=/home/oracle/bin
# work out which echo options need to be used
c=`echo "\c"`; [ "$c" = "" ] && { c="\c"; n=""; } || { c=""; n="-n"; }
if [ $# -eq 0 ] || [[ $# -eq 1 && $1 = "-" ]]; then
# if no sid has been specified, display the menu
echo "Advanced OraEnv"
echo "==============="
item=1
for database in $( grep -v "#" ${oratab}|grep -v "*"|cut -f1 -d:|awk '$0!~/^$/ {print $0}' ); do
echo $n "${item}) $database${c}"
# if the entry matches the current ORALCE_SID setting mark it with a '*'
if [ "${database}" == "${ORACLE_SID}" ]; then
echo " *"
else
echo
fi
item=$((item + 1))
done
# get the users selection
echo
echo $n "Choose: $c"
read selection
# find the correct sid for the selection
item=1
ORACLE_SID=q1w2e3r4t5y6u7i8o9p
for database in $( grep -v "#" ${oratab}|grep -v "*"|cut -f1 -d:|awk '$0!~/^$/ {print $0}' ); do
if [ $item -eq $selection ];then
ORACLE_SID=$database
fi
item=$((item + 1))
done
else
# if a sid was specified make sure it's in the oratab
if [ `grep -v "#" ${oratab}|grep -v "*"|grep "${1}:"|wc -l` -eq 1 ];then
ORACLE_SID=$1
else
ORACLE_SID=q1w2e3r4t5y6u7i8o9p
fi
fi
# set the oracle environment
if [ $ORACLE_SID != "q1w2e3r4t5y6u7i8o9p" ]; then
export ORAENV_ASK=NO
. $oraenv
export ORAENV_ASK=YES
echo "ORACLE_SID : ${ORACLE_SID}"
echo "ORACLE_HOME : ${ORACLE_HOME}"
echo "LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
echo "TNS_ADMIN : ${TNS_ADMIN}"
# look for and, if found, run the optional config script
if [ -a "${optional_script_dir}/aoe_${ORACLE_SID}" ]; then
echo "Executing optional config file..."
. ${optional_script_dir}/aoe_${ORACLE_SID}
echo "Completed execution of optional config file."
fi
# optionaly run sqlplus "/ as sysdba"
if [[ $# -eq 1 && $1 = "-" ]] || [[ $# -eq 2 && $2 = "-" ]]; then
sqlplus "/ as sysdba"
fi
else
echo "aoe error: Invalid SID or selection"
unset ORACLE_SID
unset ORACLE_HOME
fi
|