LinuxQuestions.org
Visit Jeremy's Blog.
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 02-14-2012, 12:10 AM   #1
WarChild86
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Rep: Reputation: Disabled
Environment Variables problem with Ubuntu & Tomcat


Hi friends,

I am new to Linux and i have a very pressing problem here. I am currently working on my Final Year Project.

Here's the problem:
My server is running on Ubuntu with tomcat6 installed.
I have this env variable "PREDICT_HOME" defined with the value "/home/edusys/predictSystem". I can get this variable with no problems at the shell cmd line.

Here's the problem, when i run some code in my JSP file under tomcat, i get an entire different set of variables as compared to the set i see when i run "env" at the shell. "PREDICT_HOME" doesn't come out at all, i need that variable value to proceed.

What could be the problem?? I am new to Linux.
 
Old 02-14-2012, 09:38 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,680
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
When you login you typically "source" various profiles for exmaple: /etc/profile (global for all users using sh, ksh), /etc/bashrc (global for all users using bash), cshrc (global for all users using csh), $HOME/.profile in the home directory of the sh, ksh user only for that user, $HOME/.bashrc and/or $HOME/bash_profile in the home directory of the bash user only for that user etc... In turn these profiles may be instructed to "source" other config/environment files (which could also "source" yet more things and so on...) The main job of these files is to set environment variables. A couple of very important ones set are TERM which tells it what kind of terminal to display on and PATH which tells it where to look for executable files. So long as the variable was exported it becomes available to all programs run from that login session.

On the other hand automated programs such tomcat, java, cron etc... are started in the background and will not have "sourced" the above profiles because there wasn't a login involved. Many of them will have their own configuration files that can be used to set run time environment variables. Alternatively you can start them with start scripts that either set the necessary variables or force them to "source" the profiles before startup in your start script. (Doing sourcing of profiles is sometimes ugly because setting things like TERM or other user display related variables has no meaning in a background process - it doesn't typically keep it from working but does make any log files you create show awful messages.)

As noted above another key is to insure variables set by one process are exported if needed in a subsequent one in the same process tree. Otherwise the variable is local to the process that started it.
 
1 members found this post helpful.
Old 02-14-2012, 12:06 PM   #3
WarChild86
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Wow thanks for your answer.
So can i add my env variables under some scripts like startup.sh for tomcat to export the variables?

Do you have any suggestion on what i can do to my tomcat to ensure i have the variables i need for my program?? Thanks for your help!!!
 
Old 02-14-2012, 12:14 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,680
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
Yes you can add to any script like startup.sh. Presumably by its name that is either sh, ksh or bash (often the first line in a script is an interpreter line in the form:
#!path_to_interpreter_binary
e.g.
#!/bin/bash
#!/usr/local/bin/perl
#/usr/bin/ksh
If that line exists it will let you know what interpreter will run it regardless of the shell that started it. (That is to say even if you login using the C shell (csh) if you execute a script "#!/bin/bash" as its first line the script will run in a bash shell.

Variable setting in a sh/ksh/bash script is simple:
export PREDICT_HOME=/home/edusys/predictSystem

Note that there may be other files sourced from the startup.sh script. The script or such other sourced files (or even config files the application itself recognizes) might set variables so if you set a variable but find it changed later then you might investigate those things.
 
1 members found this post helpful.
Old 02-14-2012, 12:16 PM   #5
WarChild86
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for your great advice. I will try the suggestions and revert back my findings in 1-2 days time.
Once again, thanks for your time and help!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Krecord & Setting Environment Variables Raymond C. Glassford Mandriva 4 11-21-2008 12:29 PM
Need to learn about Java, Tomcat, MySQL and environment variables GOWDASHARATH Linux - Newbie 1 06-23-2008 04:46 AM
nasm & CGI environment variables rblampain Programming 7 04-15-2007 03:01 AM
Scripts & Environment Variables geeman2.0 Linux - General 12 07-05-2005 06:10 PM
/etc/crontab & environment variables gepesz Linux - Software 3 09-03-2004 02:26 AM


All times are GMT -5. The time now is 08:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration