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

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 ...

oracle dba_hist_sysmetric_summary

found this blog is helpful to get CPU and IO statistics on oracle database. http://shob-dbadmin.blogspot.ca/2012/12/how-to-find-total-io-of-database.html courtesy to  Shomil Bansal , below are hist writing, not mine. How to find total IO of the database instance Total IO of database instance is sum of the physical reads, physical writes and redo writes. There are several views to find these values. v$sysmetric  - Reports metric values for only the most current time sample 60 secs. v$sysmetric_summary  - Reports metric values for time sample of 1 hour. v$sysmetric_history  - Reports metric values every 60 sec from the time instance is up. Better way to analyse IO using this view to take deltas between two time periods. dba_hist_sysmetric_history  - All the above views are refreshed when the instance is restarted. This view, part of AWR, stores the historical stats. I have used this view for my report. Query: ====== set lines 350...

ORA_RMAN_SGA_TARGET

assume that we lost all the files of oracle database but we do have rman backup, when trying to bring up a dummy database before restore start, I get this error. RMAN> startup nomount force; WARNING: cannot translate ORA_RMAN_SGA_TARGET value startup failed: ORA-01078: failure in processing system parameters ORA-01565: error in identifying file '+DATA/PROD/spfilePROD.ora' ORA-17503: ksfdopn:2 Failed to open file +DATA/PROD/spfilePROD.ora ORA-15056: additional error message ORA-17503: ksfdopn:DGOpenFile05 Failed to open file +DATA/prod/spfileprod.ora ORA-17503: ksfdopn:2 Failed to open file +DATA/prod/spfileprod.ora ORA-15173: entry 'spfileprod.ora' does not exist in directory 'prod' ORA-06512: at line 4 starting Oracle instance without parameter file for retrival of spfile RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =================================...