Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the correct dbase name in UNIX

Suman_7
Frequent Advisor

How to get the correct dbase name in UNIX

I have multiple databases in the HP UX box.
for example

box name : HPUX1
dbase1: dev1
dbase2:dev2
dbase3:dev3
dbase4:qa1
dbase5:qa2
dbase6:qa3


I have to promote a shell script which basically tests whether the dev database is up if it is being executed with dev env file
if the script is being executed with qa env file it has to check for qa databases.


Presently I have hardcoded the dbase name in my script for examplce:
dbase1=dev1
dbase2=dev2
dbase3=dev3


but my concern is if this script gets promoted and someone wants to execute it with qa environments then it will still check for the dev baseses dev1, dev2, dev3. How do I dynamically change these parameters if thescript is being executed in qa to qa1, qa2, qa3.


Thank You very much.


6 REPLIES
KapilRaj
Honored Contributor

Re: How to get the correct dbase name in UNIX

We keep such in a local file in every node not in the script and the script does a "cat" to this file to get the correct file.

Something like , hv a /std/local/DBS/env which has these and script looks for this file on every node.

Regds,

Kaps
Nothing is impossible
chapaya_1
Frequent Advisor

Re: How to get the correct dbase name in UNIX

Hi ,

Try with ps -ef |grep -i pmon ,
then use awk to cut the db name .

BYE
Victor Fridyev
Honored Contributor

Re: How to get the correct dbase name in UNIX

Hi,

According to Oracle rules, the DBs which work on a computer, should be written to a file called /etc/oratab.
The format of each entry of the file is:
SID:ORACLE_HOME:Y
for the DB, which should be started by dbstart, or
SID:ORACLE_HOME:N
if you don't want to start the DB by dbstart.
e.g.:
QA1:/home/oraprod/ORA8174:Y
QA2:/home/oraprod/ORA9i:N

Reading /etc/oratab file, you can obtain all SIDs and check the DB status with
ps -fuoracle|grep ora_pmon_$SID

HTH
Entities are not to be multiplied beyond necessity - RTFM
Arturo Galbiati
Esteemed Contributor

Re: How to get the correct dbase name in UNIX

Hi,
for OraSid in $(grep -E -v "^#|^$" /etc/oratab|cut -d: -f1);do
# setup the rigth Oracle environment
export ORACLE_SID=$OraSid
ORAENV_ASK=NO; . oraenv

# put your checks here

done

HTH,
Art
Ross Barton
Occasional Advisor

Re: How to get the correct dbase name in UNIX

Write a script that gets run whenever you want to administer any of your DB's. This script should read a config file with your DB names - and depending on the way it is called set up your DB name for you (using the info on the command line and the info in the config file).

Setup the config file so it exists on all the boxes that you run DB's on - then NFS mount it (if you use NFS) so you only have to maintain and publish one copy.

You can even call the script from within the .profile (at login) of any user that is used to administer a single DB. If your admin user is used to administer multiple DBs (such as is typical on ORACLE and INGRES) then you can still just call it from the command line each time you login to adminsiter a set of DB's.
Everything should be made as simple as possible, but not simpler. Albert Einstein.
Alexander M. Ermes
Honored Contributor

Re: How to get the correct dbase name in UNIX

Hi there. Perhaps this kicks off some idea :

cat /etc/oratab | while read LINE
do
case $LINE in
\#*) ;; #comment-line in oratab
*)
# Proceed only if third field is 'Y'.
if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] && [ "${Db_Name}" = "none" ]
then
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
oracle_sid=`echo $ORACLE_SID|tr "[A-Z]" "[a-z]"`

.....


Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"