LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-11-2004, 10:34 AM   #1
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Rep: Reputation: 30
change env on Linux


Hi all,

let say if I have 2 database on the Linux server and long with that I also had a third party running on the same server. Any way, what I want to ask is the following:

set env for each database, let say if I want to be on the first env along with the third party software to run ok, I have to do:

export ORACLE_SID=test1 (where test1 is the database SID of the first instance)

export SDEHOME=/home/sde/sdeexe83 (where /home/sde/sdeexe83 is the home of the software for the first instance)




so if I want to switch to the second database along with the different home for the third party sfotware I have to do the following:




export ORACLE_SID=test2 (where test2 is the database SID of the second instance)

export SDEHOME=/home/sde/sdeexe83_2 (where /home/sde/sdeexe83_2 is the home of the software for the second instance)


the question is "what can I do to switch env without typing each time, another way, the shorter way to change env)

thanks,
 
Old 02-11-2004, 12:14 PM   #2
grayswander
Member
 
Registered: Apr 2003
Location: Israel
Distribution: Gentoo
Posts: 61

Rep: Reputation: 15
The obvious way : to write a script(s).
 
Old 02-11-2004, 12:21 PM   #3
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Code:
#!/bin/sh

if [ "$1" = "1" ]; then
export ORACLE_SID=test1
export SDEHOME=/home/sde/sdeexe83 
elif [ "$1" = "2" ]; then
export ORACLE_SID=test2
export SDEHOME=/home/sde/sdeexe83_2
else
echo "no database specified"
fi
Make this executable and place it in your path.
Call it with "<filename> 1" or "<filename> 2"
 
Old 02-11-2004, 01:10 PM   #4
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Original Poster
Rep: Reputation: 30
mikeshaw,

thanks for your advises.

I did save the file as test.sh

so how do we go from here???

is that from the command prompt we do:

$./test.sh

????


once we get the executable from, what we need to do from here????


BTW, you have to my two file for the same scripts that you posted earlier???? change_env_1.sh and change_env_2.sh?????


Last edited by ashley75; 02-11-2004 at 03:18 PM.
 
Old 02-11-2004, 02:52 PM   #5
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
I'm going to say "./test.sh 1" if you want to export ORACLE_SID=test1 and "./test.sh 2" for test2

However, the naming is slightly different (i tend to not use extensions on scripts...just put them all in a specific directory in my path)..I assume it would work the same, though.
Here's my setup, for reference:
1) create a directory called "scripts" in my home
2) in ~/.bashrc add PATH=$PATH:~/scripts
3) dump all my scripts in ~/scripts
4) chmod 700 ~/scripts/*

No need to specify a path now...I just do "test 1" and it'll run ~/scripts/test with an argument of "1".
"test" isn't really a good name for a script, though, since there's already a commonly used executable called "test"
 
Old 02-11-2004, 03:15 PM   #6
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Original Poster
Rep: Reputation: 30
mikeshaw,

thanks again

ok I save the file as change_env.sh and then I issue the command:

$./change_env.sh 1


obviously the env still point to the first so when I do:

./change_env.sh 2


I check the env by tying:

$env


it still point to the first environment so it's not changing then.

could you please tell me why???
 
Old 02-11-2004, 03:24 PM   #7
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
weird....

What happens when you run it without an argument (just "change_env.sh" with no number)? Do you get the "no database specified" response?
 
Old 02-11-2004, 03:55 PM   #8
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Original Poster
Rep: Reputation: 30
yes that's what I get:



no database specified


Did I do somehting wrong???
 
Old 02-11-2004, 04:08 PM   #9
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
I don't think so. I asked about the error message just to see if the script was running at all.
If those commands work properly when you run them from commandline, then there's something wrong with my script.
Or perhaps you'd need to check env in a new shell after you run the script before you'll see the changes.
Perhaps it's reading the numbers as numbers rather than strings? Doesn't seem so, but I can't think of anything else at the moment.
Just to humor me, could you change the "1" and "2" to "one" and "two", and see if it makes a difference (if the new shell thingy doesn't work)?

Last edited by mikshaw; 02-11-2004 at 04:10 PM.
 
Old 02-11-2004, 04:22 PM   #10
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Original Poster
Rep: Reputation: 30
mikeshaw,

I did type:

$env

right after I run your script that how I find out it didn't change the env.

I did change from"1" to "one and "2" to "two", it doesn't work.
 
Old 02-11-2004, 04:23 PM   #11
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
What I was getting at was you may have to open a new terminal and check your environment from that. It's possible that the changes won't affect your current bash session
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
env problem on Linux Redhat 2.1 ashley75 Linux - General 6 03-21-2005 09:39 AM
question about Linux env ashley75 Linux - General 1 10-21-2004 09:00 AM
Environment Variable: how to change env DISPLAY in Redhat 9 lucastic Linux - General 2 07-21-2004 04:15 PM
how to change the Red Hat ENV LANG? zhgalaxy Linux - General 1 02-16-2004 07:37 PM
How to change the screen resolution in Red Hat 7.1 KDE env/ vbp1 Linux - General 2 10-11-2001 06:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration