Dynamically changing environment variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dynamically changing environment variable
# 1  
Old 11-10-2015
Dynamically changing environment variable

Linux Redhat, BASH Shell.

I want to put this in my .bash_profile

I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into .bash_profile that will change dynamically when another parameter changes?

if I do this, it only checks for $ORACLE_SID, the first time the .bash_profile is run.
ORACLE_SID=mydb
LOG_DIRECTORY=/var/opt/$ORACLE_SID/logfile.log

so
echo $LOG_DIRECTORY=/var/opt/mydb/logfile.log

If the SID changes, I need the $LOG_DIRECTORY variable in memory to change also. I don't want to do it manually. I would like the parameter to change that is from the .bash_profile

I need ORACLE_SID, to change dynamically whle the $LOG_DIRECTORY is in memory
# 2  
Old 11-10-2015
Linux, like most *ix doesn't pass the symlink data through something that can evaluate a variable expression.

I think OSX might support this though and I know that Apollo OS's did (and likely HP-UX still has some support for this). As a former Apollo user you could create a symlink with a variable as part of the link name. In fact, you could could point your entire /usr space to run off somebody else's machine by merely changing and environment variable. It was also how they allowed you to easily switch shell flavors.


It's not that Oracle didn't go totally brain dead on how they did things, it's just that they don't want to change to become more modern. Oracle "stuff" like this has been around since before most people on this forum were probably born.

Good question, but the problem isn't lack of features in the shell or OS, the problem is Oracle....
# 3  
Old 11-10-2015
By example, this would evaluate the actual value of $ORACLE_SID

Code:
LOG_DIRECTORY="/var/opt/\$ORACLE_SID/logfile.log"

Note your comment: "I need ORACLE_SID, to change dynamically whle the $LOG_DIRECTORY is in memory" seems conceptually wrong or it is not clear what you mean"
# 4  
Old 11-10-2015
How do you change the ORACLE_SID? With an alias? A script? A function? Put the path change into that script/function as well.
# 5  
Old 11-10-2015
My guess is that ORACLE_SID is changed merely by changing the value of the variable, but will wait for the OP to respond.
# 6  
Old 11-10-2015
ORACLE_SID is an environment var (site identifier) that corresponds to a particular environment.

I don't understand what you mean by dynamically changing it in memory. Generally the environment is set and you launch the environment.

Why do you want to change the SID, what is your use case?

Are you trying to get a running environment to access another environment (i.e. a shared memory segment)?



I will change my ORACLE_SID or entire oracle environment normally when I want to access a different instance/environment that is already running. Many folks will define different oracle users that have distinct environments (hence different ORACLE_SIDs).

Refer to this link:

https://asktom.oracle.com/pls/asktom...D:318216852435
# 7  
Old 11-10-2015
Love to hear from the OP.

However, as an Oracle user, I think the idea is switch SIDs without having to source in oraenv.

In other words, making switching SIDs easier.

Why switch SIDs? Maybe you have more than one instance? It's an ok use case thing.

If switching SIDs is just something done from inside of a script, I'd just set my ORACLE_SID and source in oraenv.sh, done.... but there could still be a desire for something better than this.

Imagine if ORACLE_SID could be a path. Then the SID could be the basename and the other ORACLE elements could be folders (or symlinks) off that ORACLE_SID path if env vars aren't specified, etc... just an idea. And certainly not something I expect Oracle to do.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a dynamically changing file

I want to read a constantly changing file and do some operation on text found in that file. Actually that is log file of linux system and whenever i find a matching string in that file i want to create a text file with timestamp. is it possible to read that file? here is sample output of log... (7 Replies)
Discussion started by: kashif.live
7 Replies

2. Shell Programming and Scripting

Dynamically setting of environment variable... Can it be done?

Hi all, I am fairly new to unix scripting and will like to know how to dynamically set the name of an environment variable to be used. We have a .env file where we defined the names and locations of data files, trigger files, directories .... etc Example of variables defined in .env... (4 Replies)
Discussion started by: Morelia
4 Replies

3. Red Hat

Changing Desktop Environment by mistake

Hi, I'm using fedora 15, my defualt DE is XFCE I once saw that there is a option in startup DE's that I can select and it was OPENBOX. I just wanted to test it. but after choosing it as my DE here I am. I have just access to terminal, firefox.. what's in my desktop. there is no panel here. I... (0 Replies)
Discussion started by: hoseinit
0 Replies

4. Shell Programming and Scripting

BASH - Reference external variable name dynamically

Hi there, I have included an external properties file into my BASH script via the 'source' command. I am attempting to dynamically assign a variable in the BASH script, that references the variable name within the external properties file i.e. #!/bin/bash pth=${0%/*} source... (3 Replies)
Discussion started by: mjwoodford
3 Replies

5. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

6. Shell Programming and Scripting

Adding string variable dynamically in for loop

Hi, I need to generate the text name dynamically in for loop, ex, VAR_COPY_FILE1= file path 1 VAR_COPY_FILE2= file path 2 VAR_COPY_FILE3= file path 3 for i in 1 2 3 do if then "do some process here" fi done (3 Replies)
Discussion started by: msubash26
3 Replies

7. Shell Programming and Scripting

How to read a dynamically changing file and load into Oracle?

I have a tab delimited file which has 27 character fields. The file needs to be loaded into an Oracle table. But the challenge is that everytime the file comes it may or may not have values in all 27 fields. Column Definition of the 27 fields: TYPE: Char (1) NAME: Char (30) CUSTOM_VAL: Char... (8 Replies)
Discussion started by: madhunk
8 Replies

8. Shell Programming and Scripting

changing environment variables

hi friends, i'm new to shell scripting,can i know how to change the environment variables without altering anythng in .bash_profile as the change in it is for a specific user but i want the change to be available to every user who logs in. bye. (1 Reply)
Discussion started by: amit4g
1 Replies

9. Shell Programming and Scripting

dynamically creating a variable name

Hi ! I have the following situation - ##First variable variableA=JOB_A ##bunch of other variable JOB_A_RESTART=cleanupJobA JOB_B_RESTART=cleanupJobB JOB_C_RESTART=cleanupJobC now i need a script which would - 1. take the first variable 2. create a new variable name... (2 Replies)
Discussion started by: hsahay
2 Replies
Login or Register to Ask a Question