LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-11-2006, 01:40 AM   #1
sanjeevkchopra
LQ Newbie
 
Registered: May 2006
Posts: 14

Rep: Reputation: 0
How to access evviroment variables in startup scripts


Hi All,

Can somebody tell how the value of an environment variable can made available in startup script in Linux?

I have added JAVA_HOME=/usr/java/j2sdk1.4.2_10 in /etc/profile and a shell script testEnv in /etc/init.d/.

The script testEnv looks like this:

#! /bin/sh
echo JAVA_HOME=$JAVA_HOME

When I run script with command
# /etc/init.d/testEnv
it displays the values of JAVA_HOME which was set in /etc/profile.

But when the command
# service testEnv
is run it does not display any thing.

Can somebody tell why it doesn’t displays anything OR
Where should we define JAVA_HOME so that it should be visible to startup scripts OR
How the script should be modified so that it displays the value of JAVA_HOME set in /etc/profile or somewhere, when script executed at boot level ?

Regards,
Sanjeev Kumar.
 
Old 07-11-2006, 01:57 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
/etc/profile is read when you login. When the startup scripts are run they have a cut down environment as no user is logged in. I'd set JAVA_HOME in the script itself, but set it to a symlink that gets updated to point to the real location. That way your script won't break every time you upgrade your Java install.

For example, at a shell prompt create the link:
Code:
# ln -s /usr/local/jdk1.5.0_07 /usr/local/jdk
In your script:
Code:
JAVA_HOME=/usr/local/jdk
Hope that helps...
 
Old 07-11-2006, 05:30 AM   #3
sanjeevkchopra
LQ Newbie
 
Registered: May 2006
Posts: 14

Original Poster
Rep: Reputation: 0
equivalent of chkconfig and service

Thanks gilead.
I think that soluction'll work.

I have one more question.
Can you tell solaris equivalent of chkconfig and service command of redhat liunx

Thanks and regards
Sanjeev
 
Old 07-11-2006, 02:37 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Sorry I can't - my experience with Solaris is mostly with shell scripts, not administration. The Solaris forum here at http://www.linuxquestions.org/questi...splay.php?f=20 should be able to help though.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing environment variables in startup scripts sanjeevkchopra Linux - Security 2 07-10-2006 10:16 AM
Accessing environment variables in startup scripts sanjeevkchopra Linux - General 1 07-10-2006 09:55 AM
Accessing environment variables in startup scripts sanjeevkchopra Linux - Networking 1 07-10-2006 09:54 AM
Accessing environment variables in startup scripts sanjeevkchopra Linux - Networking 1 07-10-2006 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:32 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