Skip to main content

bcfenv and $ORACLE_SID.env


#!/bin/bash
# =========================================================================
# Name ...........: /u01/dba/bin/bcfenv.sh (ugo+x)
# Function .......: Displays the Oracle BCF environment selection menu
# Usage ..........: This file is called once at log-on from bashrc, and
#                   is also called from command line by typing 'bcfenv'.
#                   The menu selection that this script displays is built
#                   dynamically from the oratab file. This file, aside from
#                   displaying the menu, also echoes back variables by
#                   calling it with the 'env' parameter eg: 'bcfenv.sh env',
#                   there is an alias in the 'bashrc' called 'echov' which
#                   calls this script in that manner.
# -------------------------------------------------------------------------
#
# History
#
# Date         Rev  Who                          Comments
# ------------ ---- ---------------------------- --------------------------
# 16-DEC-2009  01.0 Leonard Garland              Initial Release
# 00-000-0000  02.0                              for RAC env, OS is linux user: oracle/grid...
# =========================================================================
#

# *************************************************************************
# **** Variables required by this menu system, * EDIT AS REQUIRED *   *****

oratab=/etc/oratab_dba
oraenv=/usr/local/bin/oraenv
unset_variables=/u01/dba/bin/unset_oraenv.env

# *************************************************************************
# *************************************************************************

unset_var()
{

  unset TWO_TASK
  unset ORACLE_SID
  unset ORACLE_HOME
  unset WL_HOME
  unset BEA_HOME
  unset DOMAIN_NAME
  unset DOMAIN_HOME
  unset ORACLE_BASE
  unset LD_LIBRARY_PATH

  # Calls optional unset variables script, if it exists
  if [ -a "${unset_variables}" ]; then
    . $unset_variables
  fi

}

get_menu_message()
{
  temp_prefix=''
  temp_env_home=''
  temp_env_home=`dbhome "$1"`
  if [ -f ${temp_env_home}/$1.env ];
    then
      temp_prefix=`grep "MENU_MESSAGE" ${temp_env_home}/${1}.env | cut -f2 -d'=' | sed "s/\'//g;s/^[ \  ]*//;s/[ \      ]*$//"`
      if  [[ -z "$temp_prefix" ]];
        then
          echo 'No Menu Description in the Environment File'
        else
          echo ${temp_prefix}
      fi
    else
      echo 'No Environment File Found'
  fi

}



display_variables()
{

  # Sets str_invent = to all available Oracle inventories

  str_invent=''
  for i in `ls /u01/app/oraInventory/oraInst.loc*`; do
     str_invent="$str_invent|`echo $i | cut -f2 -d'_'`"
  done

  export ORA_INVENTORY=`cat /u01/app/oraInventory/oraInst.loc | grep inventory_loc | cut -d'/' -f4`

  echo
  echo "================================================================================"
  echo
  echo "               Oracle Technical Administration for"
  echo
  echo "                            `uname -n` "
  echo
  echo "Oracle Database.. : ${ORACLE_SID}"
  echo "Oracle Home...... : ${ORACLE_HOME}"
  echo "Oracle Base...... : ${ORACLE_BASE}"
  echo "WL Home ......... : ${WL_HOME}"
  echo "BEA Home ........ : ${BEA_HOME}"
  echo "Domain Name ..... : ${DOMAIN_NAME}"
  echo "Domain Home ..... : ${DOMAIN_HOME}"
  echo "Library Path..... : ${LD_LIBRARY_PATH}"
  echo "TNS Admin........ : ${TNS_ADMIN}"
  echo "Oracle Inventory. : ${ORA_INVENTORY}"
  echo
  echo "Path............. : ${PATH}"
  echo
  echo "Userid .......... : `id`"
  echo
  echo "================================================================================"
  echo "To set Oracle environment..type 'bcfenv' ,builds dynamic menu from oratab"
  echo "To change inventory from 'bcfenv', type ' inv' after selection eg: '3 inv'"
  echo "You can also...............type '. oraenv'   ,Oracle standard environment setup"
  echo "To set inventory manually..type . useorainv [${str_invent}]),changes inventory"
  echo "================================================================================"

}


clear_oracle_environment()
{
  if [ ${ORACLE_HOME:-0} = 0 ];
    then
      OLDHOME=$PATH
    else
      OLDHOME=$ORACLE_HOME
  fi

  unset_var

  # --- Remove ORACLE_HOME from PATH if there is one ---

  export ORACLE_HOME=""
  case "$OLDHOME" in
      "")       OLDHOME=$PATH ;;        #This makes it so that null OLDHOME can't match
  esac                                  #anything in next case statement

  case "$PATH" in
      *$OLDHOME/bin*)   PATH=`echo $PATH | \
                            sed "s;$OLDHOME/bin;$ORACLE_HOME;g"`
      ;;
      *$ORACLE_HOME/bin*)
      ;;
      *:)                       PATH=${PATH}$ORACLE_HOME/bin:
      ;;
      "")                       PATH=$ORACLE_HOME/bin
      ;;
      *)                        PATH=$PATH:$ORACLE_HOME/bin
      ;;
  esac

  export PATH=`echo $PATH | \sed 's;::;:;g' | \sed 's/:$//'`
  unset ORACLE_HOME

}


display_menu()
{
unset_var
# Set the echo
c=`echo "\c"`; [ "$c" = "" ] && { c="\c"; n=""; } || { c=""; n="-n"; }

echo "  "
echo "  "
echo "================================================================================"
echo "  "
echo "               Oracle Technical Administration for"
echo "  "
echo "                            `uname -n` "
echo
  item=1
cat $oratab|grep -v "grid" | while read LINE
do
case $LINE in
  *MENU_INSERT*) menu_line=`echo $LINE | grep "MENU_INSERT" | cut -f2 -d'=' | sed "s/\'//g;s/^[ \       ]*//;s/[ \      ]*$//"`
                 echo -e "\033[36m$menu_line"
                 tput sgr0
                 ;;
            \#*) ;;
              *) database=`echo $LINE |cut -f1 -d:|awk '$0!~/^$/ {print $0}'`
                 if [ "$database" != '*' ]; then
                   if [ "$database" != '' ]; then
                     prefix_message=`get_menu_message $database`
                     tmp1=`echo ${item}') '         | cut -c1-3`
                     tmp1=`echo ${tmp1}" ($database)                  " | cut -c1-20`
                     if [ "${database}" == "${ORACLE_SID}" ];
                       then
                         echo -e $n " ${tmp1}" '\E[37;44m'"\033[1mCurrent\033[0m" ${prefix_message}${c}
                         tput sgr0
                         echo
                        else
                          echo $n " ${tmp1}         ${prefix_message}${c}  "
                          echo
                     fi
                     item=$((item + 1))
                   fi
                 fi
esac
done

# read user input
echo
echo ' Select "0" To Clear Oracle Environment Variables'
echo
echo " Press ENTER with no selection to exit without changes"
echo
echo $n "Select option: $c"
read selection

# Check to see if catalog flag should be set
function checkstr
{
  a=${1/$2*/}
  if [ "$1" = "$a" ]
    then
      return 1
    else
      return 0
  fi

}

set_catalog=0
if checkstr "$selection" "inv"
  then
    set_catalog=1
    selection=`echo $selection | sed 's/inv//' | sed 's/^[ \    ]*//;s/[ \      ]*$//'`
fi

# fix user input if null, to supress errors
if [ ! -n "$selection" ] ; then
  selection=900
fi

# fix user input if not number, to supress errors
b=`echo $selection | /usr/bin/tr -dc  '[:digit:]' `

if [[ "$b" != "$selection" ]] ; then
  selection=901
fi

# find the correct sid for the selection
item=1
TEMP_ORACLE_SID=OracleSidNotSet
for database in $( grep -v "#" ${oratab}|grep -v "*"|grep -v "grid"|grep -v "MENU_INSERT"|cut -f1 -d:|awk '$0!~/^$/ {print $0}' ); do
  if [ $item -eq $selection ] ; then
    TEMP_ORACLE_SID=$database
  fi
  item=$((item + 1))
done

# set the oracle environment variables if a valid selection has been made
if [ $TEMP_ORACLE_SID != "OracleSidNotSet" ];
  then
    temp_env_home=''
    temp_env_home=`dbhome "${TEMP_ORACLE_SID}"`
    if [ -a "${temp_env_home}/${TEMP_ORACLE_SID}.env" ];
      then
        echo
        echo "       Executing file: ${temp_env_home}/${TEMP_ORACLE_SID}.env"
        clear_oracle_environment
        export ORACLE_INVENTORY_CAT='is_not_set'
        . ${temp_env_home}/${TEMP_ORACLE_SID}.env
        # set OAR_INVENTORYi
        #echo $set_catalog
        #echo "set_catalog"
        if [ $set_catalog = 1 ];
          then
            if [ -f "/u01/app/oraInventory/oraInst.loc_${ORACLE_INVENTORY_CAT}" ] ;
              then
                #rm /var/opt/oracle/oraInst.loc
                ln -s /u01/app/oraInventory/oraInst.loc_${ORACLE_INVENTORY_CAT} /u01/app/oraInventory/oraInst.loc
                echo
                echo "       Setting Oracle inventory"
              else
                if [ "$ORACLE_INVENTORY_CAT" != 'is_not_set' ];
                  then
                    echo
                    echo -e "\033[31m       Unable to set Oracle inventory, ORA_INVENTORY (" "\033[36m${ORACLE_INVENTORY_CAT}" "\033[31m), does not exist"
                    tput sgr0
                  else
                    echo
                    echo -e "\033[31m       Unable to set Oracle inventory, no variable in the environment file"
                    tput sgr0
                fi

            fi
        fi
      else
        echo
        echo "       No environment file found, using 'oraenv' to set SID"
        echo
        if [ $set_catalog = 1 ]; then
          echo -e "\033[31m       Unable to set Oracle inventory, no environment file found"
          tput sgr0
        fi
        clear_oracle_environment
        ORACLE_SID=${TEMP_ORACLE_SID}
        export ORAENV_ASK=NO
        . $oraenv
        export ORAENV_ASK=YES
      fi
  else
    # List of exit errors
    case $selection in
      0) echo
         echo "       Clearing Oracle environment variables"
         clear_oracle_environment
         if [ $set_catalog = 1 ]; then
           echo
           echo -e "\033[31m       Set Oracle inventory is not allowed when clearing environment variables"
           tput sgr0
         fi
         ;;
    900) echo
         echo "       Exiting without changes"
         if [ $set_catalog = 1 ]; then
           echo
           echo -e "\033[31m       Set Oracle inventory is not allowed without a database selection"
           tput sgr0
         fi
         ;;
    901) echo
         echo -e "\033[31m       An invalid character has been entered, exiting without changes"
         tput sgr0
         ;;
      *) echo
         echo -e "\033[31m       Not a valid menu selection, exiting without changes"
         tput sgr0
         ;;
    esac
fi

# Removes double :: from PATH left by oraenv and other apps
export PATH=`echo $PATH | \sed 's;::;:;g'`

unset ORACLE_INVENTORY_CAT

display_variables

}

if [ "$1" = "env" ];
  then
    display_variables
  else
   display_menu
fi


export SQLPATH=/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin
# == EOF ==================================================================

bash-4.1>more FCGENP.env
#!/usr/bin/bash
# =========================================================================
# Name ...........: FCGENP.env
# Function .......: Setup environment for Grid Control Agent
# Usage ..........: This file should be located in its corresponding
#                   Oracle Home, and should have the exact name of the SID
#                   entry in the oratab file with .env extention
# -------------------------------------------------------------------------
#
# =========================================================================
#

# Removes old ORACLE_HOME from PATH

  . /u01/dba/bin/remove_path.sh

# The menu message varaible is extracted by grep, it is impotant that if
# remains in the same format with single quotes and no unusual characters
# the message will be cut from the = sign to the right side EOL

  MENU_MESSAGE='FCGENP1 on RAC production'

  export ORACLE_SID=FCGENP1
  export ORACLE_INVENTORY_CAT=''
  export ORACLE_BASE=/u01/app/oracle
  export ORACLE_HOME=/u01/app/oracle/product/12.1.0/
  export LD_LIBRARY_PATH=$ORACLE_HOME/lib
  export PATH=$PATH:$ORACLE_HOME/bin

# == EOF ======================================================================


Comments

Popular posts from this blog

non-existent process lock port on windows server

I have a database link created between oracle and sqlserver using oracle tg4odbc, the product is installed on windows server and run as service "OracleOraGtw11g_home1TNSListener", but sometime the service cannot started, the root cause of this problem is that the port number 1521 is used by an non-existent process. The first step is to use netstat -bano|find "1521" to get the process id, in my case it's 5844, which shows the connection is from my oracle server 10.8.0.169 H:\>netstat -bano|find "1521"   TCP    0.0.0.0:1521           0.0.0.0:0              LISTENING       5844   TCP    10.14.45.33:1521       10.8.0.169:42987       ESTABLISHED     5844 however the process id does not show in either task manager or process explorer. The next step is to run tcpview, which shows non-existent under process column, there are three rows, two show status as "listening", the other one shows status "established", right click and k

Opatch apply/lsinventory error: oneoff is corrupted or does not exist

I am applying the quarterly patch for 19c RDBMS, I tried using napply but failed, but somehow it corrupted the inventory though nothing applied. further apply and lsinventory command ran into error like this: $ ./OPatch/opatch lsinventory Oracle Interim Patch Installer version 12.2.0.1.21 Copyright (c) 2020, Oracle Corporation.  All rights reserved. Oracle Home       : /u02/app/oracle/19.0.0 Central Inventory : /u01/app/oraInventory    from           : /u02/app/oracle/19.0.0/oraInst.loc OPatch version    : 12.2.0.1.21 OUI version       : 12.2.0.7.0 Log file location : /u02/app/oracle/19.0.0/cfgtoollogs/opatch/opatch2020-09-08_13-35-59PM_1.log Lsinventory Output file location : /u02/app/oracle/19.0.0/cfgtoollogs/opatch/lsinv/lsinventory2020-09-08_13-35-59PM.txt -------------------------------------------------------------------------------- Inventory load failed... OPatch cannot load inventory for the given Oracle Home. LsInventorySession failed: Unable to create patchObject Possible ca

shell script to clean up oracle dumpfile

https://github.com/iacosta/personal/blob/master/shells/cleanhouse.sh #!/bin/ksh # # Script used to cleanup any Oracle environment. # # Cleans:      audit_file_dest #              background_dump_dest #              core_dump_dest #              user_dump_dest #              Clusterware logs # # Rotates:     Alert Logs #              Listener Logs # # Scheduling:  00 00 * * * /networkdrive/dba/scripts/purge/cleanup.sh -d 7 > /u01/dba/bin/cleanup.log 2>&1 # # Created By:  Lei Dao # # # RM="rm -f" RMDIR="rm -rf" LS="ls -l" MV="mv" TOUCH="touch" TESTTOUCH="echo touch" TESTMV="echo mv" TESTRM=$LS TESTRMDIR=$LS SUCCESS=0 FAILURE=1 TEST=0 HOSTNAME=`hostname` ORAENV="oraenv" TODAY=`date +%Y%m%d` ORIGPATH=/usr/local/bin:$PATH ORIGLD=$LD_LIBRARY_PATH export PATH=$ORIGPATH # Usage function. f_usage(){   echo "Usage: `basename $0` -d DAYS [-a DAYS] [-b DAYS] [