[clue] env variables

dennisjperkins at comcast.net dennisjperkins at comcast.net
Mon Jun 24 14:21:39 MDT 2013


I'm guessing your script began with #!/bin/bash. That spawns a new process with its own environment inherited from th parent. JAVA_HOME and PATH were set and exported in your script, so those values are set in your script's environment (and for any programs that it called). It does not set values in the parent environment. Try running it without #!/bin/bash. I think that will run the script in the same environment. Note that this means that your script can only be called from bash. 


I have a few comments on the scripts. 

1. Why the sleep statements? They don't appear to do anything useful. 

2. You don't need to use touch to create the file. 

3. You probably want to use > to write the first line to /etc/profile.d/00_jdk.sh. If the file already exists, you're appending your string. Using > will erase the file if it exists and write the string to an empty file. 

4. You could use a HERE doc statement for all of the echoes you used to create 00_jdk.sh. 
----- Original Message -----
From: "Mark G. Harvey" <markgharvey at yahoo.com> 
To: "CLUEmessage CLUE" <clue at cluedenver.org> 
Sent: Monday, June 24, 2013 1:54:14 PM 
Subject: [clue] env variables 



CLUE experts, 

This puzzle is likely simple for you folks, but it has me stumped. I've done considerable digging but have found mixed advice. 

I've created a script to download from a local repo via wget an rpm to install JDK ... no problem there. 

Here's the part I can't get right ... setting the variables so I can run scripts to install Tomcat ... Any attempt will bomb if it can't find /usr/java/jdk1.7.0_21/bin 


# set JAVA_HOME variable ... tried in vain 
echo "setting JAVA_HOME variable variable for the session" 
JAVA_HOME=/usr/java/jdk1.7.0_21 
# export JAVA_HOME variable ... tried in vain 
echo "exporting JAVA_HOME variable variable for the session" 
export JAVA_HOME=/usr/java/jdk1.7.0_21 
echo "JAVA_HOME variable: $JAVA_HOME" 

# set PATH variable for the session ... tried in vain 
echo "setting PATH variable for the session" 
PATH=$PATH:/usr/java/jdk1.7.0_21/bin 
# export PATH variable for the session 
echo "exporting PATH variable for the subsequent sessions & processes" 
export PATH=$PATH:/usr/java/jdk1.7.0_21/bin 
echo "show PATH variable: $PATH" 

sleep 3 # wait 

# create script to set JAVA_HOME & PATH variables in /etc/profile.d/00_jdk.sh script for all accounts 
# use echo command with single quotes to write the literal statement to the script 
touch /etc/profile.d/00_jdk.sh 
echo '#!/bin/bash' >> /etc/profile.d/00_jdk.sh 
echo '# set JAVA_HOME in /etc/profile.d/00_jdk.sh script for all accounts' >> /etc/profile.d/00_jdk.sh 
echo 'JAVA_HOME=/usr/java/jdk1.7.0_21' >> /etc/profile.d/00_jdk.sh 
echo '# set PATH in /etc/profile.d/00_jdk.sh script for all accounts' >> /etc/profile.d/00_jdk.sh 
echo 'PATH=$PATH:/usr/java/jdk1.7.0_21/bin' >> /etc/profile.d/00_jdk.sh 

sleep 3 # wait 

echo "review contents of /etc/profile.d/00_jdk.sh" 
cat /etc/profile.d/00_jdk.sh 


... results of install ... added some blank lines for readability ... 

[root at 87148-mondev01 ~]# ./DEV_install_jdk1.7-1.0.0.sh 
installation: Oracle/Sun jdk 1.7 64-bit 
remount /tmp with execute privledge 
changed to /tmp 
Pulling package from Artifactory Repo Management Server 
--2013-06-24 13:24:38-- https://<RepoHost>/artifactory/simple/ext-release-local/oracle/jdk/7u21-linux/jdk-7u21-linux-x64.rpm 
Resolving <RepoHost>... 10.33.44.10 
Connecting to <RepoHost>|10.33.44.10|:443... connected. 

HTTP request sent, awaiting response... 200 OK 

Length: 85388149 (81M) [application/x-rpm] 
Saving to: “jdk-7u21-linux-x64.rpm” 

100%[=======================================================================================================================================>] 85,388,149 52.7M/s in 1.5s 

2013-06-24 13:24:40 (52.7 MB/s) - “jdk-7u21-linux-x64.rpm” saved [85388149/85388149] 

jdk downloaded 
check /tmp/ contents for jdk 
-rw-r--r--. 1 root root 85388149 Jun 6 16:46 jdk-7u21-linux-x64.rpm 
install jdk rpm 
Preparing... ########################################### [100%] 
package jdk-2000:1.7.0_21-fcs.x86_64 is already installed ........ due to subsequent running of this script 
install jdk complete 

setting JAVA_HOME variable variable for the session 
exporting JAVA_HOME variable variable for the session 

... when tested in the script, the correct answer shows up ... 

JAVA_HOME variable: /usr/java/jdk1.7.0_21 

setting PATH variable for the session 
exporting PATH variable for the subsequent sessions & processes 

... when tested in the script, the correct answer shows up ... 


show PATH variable: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.7.0_21/bin:/usr/java/jdk1.7.0_21/bin 

review contents of /etc/profile.d/00_jdk.sh 
#!/bin/bash 
# set JAVA_HOME in /etc/profile.d/00_jdk.sh script for all accounts 
JAVA_HOME=/usr/java/jdk1.7.0_21 
# set PATH in /etc/profile.d/00_jdk.sh script for all accounts 
PATH=$PATH:/usr/java/jdk1.7.0_21/bin 
remount /tmp removing execute privledge 
finished 


... after script runs, when tested from CLI, variables not not correct ... 

[root at 87148-mondev01 ~]# echo $JAVA_HOME 

[root at 87148-mondev01 ~]# echo $PATH 
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 



[root at 87148-mondev01 ~]# exit 
logout 

[vwadmin at 87148-mondev01 ~]$ su - 
Password: 


... now the variable additions show up ... they come from the /etc/profile.d/00_jdk.sh script created as part of the JDK download & install ... 

[root at 87148-mondev01 ~]# echo $PATH 
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_21/bin:/root/bin 

[root at 87148-mondev01 ~]# echo $JAVA_HOME 
/usr/java/jdk1.7.0_21 



... How can I get the variables to be available for the current root session & usable for subsequent installations? Trying to avoid the logout / login ... 



Thanks for your help. 

_______________________________________________ 
clue mailing list: clue at cluedenver.org 
For information, account preferences, or to unsubscribe see: 
http://cluedenver.org/mailman/listinfo/clue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20130624/b520bc8b/attachment-0001.html 


More information about the clue mailing list