ORASET script


This script works similar to ORAENV script supplied with Oracle, however it has additional benefits such as listing the contents from oratab file, so one doesn't have to type the database name, but rather just pick a number belonging to the database. This script was tested in BASH on Linux. On other platforms it will require additional modifications, fur sure requiring modifications for the environment variables. Just like in ORAENV script, you will need to type "." in front of the scritp to set the environment.
Usage Example:


     $ . oraset
     Oratab Entries:
         #             DATABASE                              ORACLE_HOME
     -----   ------------------   --------------------------------------
         1             devastro          /opt/oracle/product/10.2.0/db_2
         2             tstastro          /opt/oracle/product/10.2.0/db_2
         3             devpsoft          /opt/oracle/product/10.2.0/db_2

     Choose Database [ 1 - 3 ]   2
     tstastro/testora1->


Script contents:


#!/bin/ksh
# This script sets environment for Oracle Databases. It is similar to that of
# oraenv, except it is improved. It automatically sets environment if only one
# database is found in the oratab file. It also displays databases from the
# oratab file, so you don't have to type in the database name.
#
# Author: Mike Rudnik
# Date: July 9, 2007

if [ `uname -s` = SunOS ]
then
   ORATAB=/var/opt/oracle/oratab
else
   ORATAB=/etc/oratab
fi

if [ -s "$ORATAB" ]
then
echo "Oratab Entries:"
echo " # DATABASE ORACLE_HOME"
echo "-----    ------------------    --------------------------------------"
CURSOR=1
while read LINE
do
   case $LINE in
   \#*) ;; #comment line
   "") ;; #null line
   *)
   LASTSID=`echo $LINE | cut -f1 -d":"`
   LASTHOME=`echo $LINE | cut -f2 -d":"`
   printf "%5s %20s %40s\n" $CURSOR $LASTSID $LASTHOME
   CURSOR=`expr $CURSOR + 1`
   ;;
   esac
done < $ORATAB
if [ $CURSOR -eq 2 ]
then
echo""
echo "only one database found in oratab..."
export ORACLE_SID=$LASTSID
export ORACLE_HOME=$LASTHOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib:/usr/lib64:/lib64:/lib:/usr/lib
SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
SQLPATH=$ORACLE_HOME/rdbms/admin:$ORACLE_HOME/sqlplus/admin
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
PATH=/opt/oracle/local/bin:/usr/openwin/bin:/usr/sbin:/usr/bin:/usr/ucb:/etc:/bin:/sbin:$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$ORACLE_HOME/jdk/jre/bin:$ORACLE_HOME/Apache/Apache/bin:$ORACLE_HOME/Apache/perl/bin:/usr/local/bin:/bin:/sbin
`set -o vi`
PS1="$ORACLE_SID/`uname -n`-> "
alias rm="rm -f"
else
echo ""
echo -n "Choose Database [ 1 - "`expr $CURSOR - 1`" ] "
read SELECTION

if ( echo $SELECTION | egrep '[:alpha:]|[:cntrl:]|[:graph:]|[:punct:]' >> /dev/null )
then
   # Selection is not numeric
   echo "Invalid Selection"
   return
fi

# Selection is higher then number of entries in oratab
if [ "$SELECTION" -ge "$CURSOR" ]
then
   echo "Invalid Selection"
   return
fi

#selection is lower then 1
if [ "$SELECTION" -lt 1 ]
then
   echo "Invalid Selection"
   return
fi
if [ -s "$ORATAB" ]
then
   NEWCURSOR=1
   while read LINE
   do
   case $LINE in
   \#*) ;; #comment line
   "") ;; #null line
   *)
   LASTSID=`echo $LINE | cut -f1 -d":"`
   LASTHOME=`echo $LINE | cut -f2 -d":"`
   if [ "$SELECTION" -eq "$NEWCURSOR" ]
   then
export ORACLE_SID=$LASTSID
export ORACLE_HOME=$LASTHOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib:/usr/lib64:/lib64:/lib:/usr/lib
SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
SQLPATH=$ORACLE_HOME/rdbms/admin:$ORACLE_HOME/sqlplus/admin
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
PATH=/opt/oracle/local/bin:/usr/openwin/bin:/usr/sbin:/usr/bin:/usr/ucb:/etc:/bin:/sbin:$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$ORACLE_HOME/jdk/jre/bin:$ORACLE_HOME/Apache/Apache/bin:$ORACLE_HOME/Apache/perl/bin:/usr/local/bin:/bin:/sbin
`set -o vi`
PS1="$ORACLE_SID/`uname -n`-> "
alias rm="rm -f"
return
fi
NEWCURSOR=`expr $NEWCURSOR + 1`
;;
esac
done < $ORATAB
fi
fi
else
echo "Unable to Find Oratab"
fi




Copyright © 2007, All rights reserved by RudnikConsulting Inc