Set Oracle Environmental Variable !!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set Oracle Environmental Variable !!
# 1  
Old 02-17-2006
Set Oracle Environmental Variable !!

Can someone send me a shell script to set all Oracle environment variable which is working.

I have the following script which works but not 100%. Please advice what you think is wrong.

Code:
if [ -t 0 ]                             # Command executed from a terminal
then
        ORACLE_SID=""
        while [ -z "${ORACLE_SID}" ]
        do
                tput clear; tput rev
                echo "Valid Oracle SIDs are :"
                tput rmso
                for SID in `cat /etc/oratab|grep -v "^#"|cut -f1 -d: -s`
                do
                        echo "                  ${SID}"
                done
                DEFAULT=`cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1`
                echo "\nEnter the Oracle SID you require (def: $DEFAULT): \c"
                read ANSWER
                [ "${ANSWER}" = "" ] && ANSWER=$DEFAULT
                export ORACLE_SID=`grep "^${ANSWER}:" /etc/oratab|cut -d: -f1 -s`
                export ORACLE_HOME=`grep "^${ANSWER}:" /etc/oratab|cut -d: -f2 -s`
                if [ "${ORACLE_SID}" = "" ]
                then
                        echo "\n\n              ${ANS}: Invalid Oracle SID  \c"
                        sleep 2
                fi
        done
else                                    # Set to first entry in oratab
        export ORACLE_SID=`cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1`
        export ORACLE_HOME=`cat /etc/oratab|grep -v "^#"|cut -d: -f2 -s|head -1`
fi

export ORACLE_SID=$ORACLE_SID
export ORACLE_HOME=$ORACLE_HOME
export PATH=${PATH}:${ORACLE_HOME}/bin
#ORAENV_ASK=NO
#. ${ORACLE_HOME}/bin/oraenv
#ORAENV_ASK=
echo
echo Oracle SID is now `tput rev`$ORACLE_SID`tput rmso`, Oracle Home is `tput rev`$ORACLE_HOME`tput rmso`
echo


When I run it it works as follows..
./setenv.sh
HTML Code:
Valid Oracle SIDs are :
                        mdmop
                        mdmt
                        mdmp

Enter the Oracle SID you require (def: mdmop): mdmt

Oracle SID is now mdmt, Oracle Home is /u001/app/oracle/product/9.2/home


 ga016dhd -> echo $ORACLE_SID
mdmop                                <== Not really set to mdmt(even if it said it is)
 ga016dhd -> echo $ORACLE_HOME
/u001/app/oracle/product/9.2/home
 [/home/oracle/script - oracle]

I think when the script executes it does execute export ORACLE_SID=$ORACLE_SID based on the values passed but once it is done executing the default values was set back ???? any reason why ??
# 2  
Old 02-17-2006
Have you "sourced" the script?

It works fine for me when I use:
Code:
. ./setenv.sh

It still need to be run similarly to /usr/local/bin/oraenv
# 3  
Old 02-17-2006
Quote:
Originally Posted by tmarikle
Have you "sourced" the script?
What doe you mean "sourced" ??

If I run it this way I get the following error.
Code:
ga016dhd -> . ./setenv.sh
sh: 1: Parameter not set.
[/home/oracle/script - oracle]
ga016dhd ->

# 4  
Old 02-17-2006
When you execute a script with a period like so:
Code:
. ./setenv.sh

The script is executed as though you typed the commands in on the command line and your environment variables effectively extend past the end of your script.

As far as your error is concerned, I don't know what is happening. I ran it in Korn shell; yours appears to be a Bourne shell.

Last edited by tmarikle; 02-17-2006 at 05:38 PM.. Reason: spelling
# 5  
Old 02-22-2006
maybe privileges

probably the user that you're using to execute script does not have prvileges on the oracle binaries. The user needs to belongs to the group (ej. dba) that usually is created previously - to the binaries installation?
once the user has privileges - the environmental variables can be "set". Another form is defining the environmental variables in .profile (file) of the user. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<< Environmental Variables are not set when script completes >>

Hi Team, I have a wrapper script which i have pasted below, it internally calls one python script to generate Environmental in a file called /home/oracle/myenv.sh, when i execute this script via wrapper script, its not reflecting in my current session, still showing old env variables. any... (2 Replies)
Discussion started by: kamauv234
2 Replies

2. Shell Programming and Scripting

Issue with cron and environmental variable

My shell script it.sh.I am calling bip.sh from it.sh #!/bin/sh ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH today=`date "+%m-%d-%Y %H:%M:%S"`; export today CUR_DIR=$1; export CUR_DIR LOG_FILE=$CUR_DIR/error.log;... (4 Replies)
Discussion started by: rafa_fed2
4 Replies

3. Shell Programming and Scripting

Clearing a environmental variable

i set a variable from the command line: export GANG="james,roy,martin" i can access this variable ($GANG) from a script. but each time i run the script, the variable keeps getting bigger. more info keeps getting added to it. Is there anyway i can make the $GANG variable contain the... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

set oracle variable in function

Hi, I have a function that is suposed to generate a AWR report: #-----------------------# gen_awr() #-----------------------# { sqlplus -s admin/admin@OCEAN11<<ENDOFSQL define num_days = '' define report_type = "html" define begin_snap =$snap1 define end_snap =%snap2 define... (1 Reply)
Discussion started by: amitlib
1 Replies

5. UNIX for Advanced & Expert Users

Environmental variable

i want to set environmental variables in solaris and redhat. it should show the current directory and the default shell should be bourne shell. along with it should show the hostname.. like this hostname{/home/vipin/data}# ifconfig Thanks in advanced.:wall: Please use code tags.... (1 Reply)
Discussion started by: vipinkumarr89
1 Replies

6. Shell Programming and Scripting

Setting Environmental Variable

I have a request from a programmer to set an env variable for him. I know how to do it for bash shell by adding the following line to .bash_profile export $VAR=/home/code/project/ But this will be applicable only when he is in his bash shell. What is the procedure to be followed to make... (2 Replies)
Discussion started by: Tuxidow
2 Replies

7. UNIX for Dummies Questions & Answers

SQL loader script - ORACLE environmental variable

I am new in unix.. I am running a sql loader script where I have to specify the data file path but the file name contains spaces in it so giving error multiple arguments I have tried it with "" and '' but does n't work the command is : $ORACLE_HOME/bin/sqlldr... (1 Reply)
Discussion started by: Sandip Dey
1 Replies

8. Shell Programming and Scripting

Oracle environmental variables in shells script

Hi, Getting below error on executing the shell script which initiates sqlplus How to set oracle enviornment variables in the shell script ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

9. Shell Programming and Scripting

How to get the value of a variable which is having another value in environmental script?

Dear Folks, I am facing an issue in getting a value of a variable.Let me explain the scenario. I am having a list file say files.list in which I have mentioned 1 FILE1 2 FILE2 Then I am having an set_env.ksh in which I mentioned FILE1=/clocal/data/user/userdata.txt... (4 Replies)
Discussion started by: dinesh1985
4 Replies

10. Shell Programming and Scripting

Environmental Variable

Hi, I'm exporting an environmental variable from a C program using putenv function. I'm calling the exe of the C program from shell script. But when I display the environmental variables from the Shell script, My varaible is not getting displayed. Can anyone please tell me how to get it in... (2 Replies)
Discussion started by: janemary.a
2 Replies
Login or Register to Ask a Question