SHARE
Facebook X Pinterest WhatsApp

Connect to Database Without Setting Environment

Dec 5, 2005

>>Script Language and Platform: Oracle
This script will gather the information from /var/opt/oracle/oratab, will set the environment and will prompt you to type a valid sid.

Author: Mssvng Narasimham Softenger India Pvt. Limited

#!/bin/sh
cls
echo “Available SIDs :- n”
sids=`ps -ef | grep pmon | grep -v grep |awk -F”_” ‘ { print $3 }’ `
echo $sids
echo “nnEnter from above : c”
read ORACLE_SID
test=`echo $sids | grep “$ORACLE_SID” | wc -l`
if [ $test -eq 1 ]; then
ORACLE_HOME=`grep “$ORACLE_SID” /var/opt/oracle/oratab | cut -d: -f2`
if [ “$ORACLE_HOME” = “” ]; then
echo “ORACLE_SID not in oratab !”
exit
fi
PATH=$ORACLE_HOME/bin:/usr/bin
export ORACLE_HOME PATH ORACLE_SID
echo “nEnvironment set
as…nnORACLE_SID=$ORACLE_SIDnORACLE_HOME=$ORACLE_HOMEnPATH=$PATHn”
usr=`id | awk -F”)” ‘ { print $1 } ‘ | awk -F”(” ‘ {print $2} ‘`
if [ “$usr” = “root” ]; then
su oracle -c “sqlplus ‘/ as sysdba'”
exit
elif [ “$usr” = “oracle” -o “$usr” = “orbit” ] ; then
sqlplus ‘/ as sysdba’
else
sqlplus
fi
else
echo “Stupid Enter Valid SID !”
fi



Disclaimer:
We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
“as -is”, without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose…

Disclaimer Continued

Back to Database Journal Home

Recommended for you...

What Backups Do I Have?
Gregory Larsen
May 12, 2021
Improving the Performance of a Table Variable using Optimizer Hint RECOMPILE
Gregory Larsen
Apr 1, 2021
TYPE Definition Change in Oracle 21c
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.