LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   Exporting Variables from Other Profiles (https://www.linuxquestions.org/questions/red-hat-31/exporting-variables-from-other-profiles-4175438422/)

cyoung75 11-23-2012 06:36 AM

Exporting Variables from Other Profiles
 
Hi

I'm trying to put together an init script to stop and start Ingres on a few machines. The problem is that the hosts have differently engineered Ingres installations so the bin type folders are in different locations.

Ideally I would like a '1 script fits all' and the idea we were working with was calling the .profile of the ingres user which always sits in /home/ingres.

The script I have so far is as follows:

Code:

su - ingres -c ". $HOME/.profile"
 
echo $II_SYSTEM
echo $PATH
echo $LD_LIBRARY_PATH

the problem is, the echo commands are showing the variables for root and not for ingres.

If I go through this step by step I get the expected results i.e. the ingres variables.

Can anyone please help?

pan64 11-23-2012 06:40 AM

$HOME is evaluated as the home of the current user (=root). Probably you would write ~ingres/.profile instead
Also the result of -c ". command" will be valid only inside the su - ingres shell, after returning to root you will loose that settings. Probably you only need . ~ingres/.profile without su - ingres -c

cyoung75 11-23-2012 06:48 AM

Quote:

Originally Posted by pan64 (Post 4835459)
$HOME is evaluated as the home of the current user (=root). Probably you would write ~ingres/.profile instead
Also the result of -c ". command" will be valid only inside the su - ingres shell, after returning to root you will loose that settings. Probably you only need . ~ingres/.profile without su - ingres -c

thanks for that

I had already considered running the profile without the su command but didn't want to break roots profile because PATH and LD_LIBRARY_PATH already exist. Is that likely to happen?

pan64 11-23-2012 06:54 AM

If you really want to say thanks please press YES in the bottom right corner.

usually the profiles (like ~ingres/.profile) will only extend PATH and LD_LIBRARY_PATH, that will not cause any problem, but if you are in doubt just check it!

chrism01 11-26-2012 02:23 AM

The main point is that as soon as this line completes
Code:

su - ingres -c ". $HOME/.profile"
you've exited the ingres env and are back to root.
You need to put everything you need into a script and than call it like you called the profile file.


All times are GMT -5. The time now is 07:57 AM.