Link to home
Start Free TrialLog in
Avatar of Jason Yu
Jason YuFlag for United States of America

asked on

how could I change JAVA_HOME in all these files

I am upgrading the JAVA_HOME parameter in a oracle application server.

I need change the string JAVA_HOME="/usr/java/jdk1.6.0_18" to JAVA_HOME="/usr/java/jdk1.7.0_45" in all of the following files.

Is there a way I can make a script to backup each file and update each file.

Thanks.


[forms@solaris middleware]$ find . -type f -name "*.sh" -exec grep -il JAVA_HOME {} \;
./utils/clone/clone.sh
./utils/clone/restore.sh
./utils/uninstall/uninstall.sh
./utils/bsu/bsu.sh
./utils/quickstart/quickstart.sh
./FormsHome/bin/runProvisioningAntTasks.sh
./FormsHome/sqldeveloper/ide/bin/launcher.sh
./FormsHome/oui/bin/runSSHSetup.sh
./oracle_common/sysman/deploy/agentdeploy/remoteif/resources/scripts/sshConnectivity.sh
./oracle_common/modules/oracle.ovd_11.1.1/oimtemplates/extendadschema.sh
./oracle_common/bin/SSLGenCA.sh
./oracle_common/bin/WLS_SSL_Client_Config.sh
./oracle_common/bin/pasteConfig.sh
./oracle_common/bin/SSLServerConfig.sh
./oracle_common/bin/libovdconfig.sh
./oracle_common/bin/pasteBinary.sh
./oracle_common/bin/libovdadapterconfig.sh
./oracle_common/bin/extractMovePlan.sh
./oracle_common/bin/obfuscatePassword.sh
./oracle_common/bin/copyBinary.sh
./oracle_common/bin/SSLClientConfig.sh
./oracle_common/bin/WLS_SSL_Server_Config.sh
./oracle_common/bin/copyConfig.sh
./oracle_common/bin/OVD_SSL_Server_Config.sh
./oracle_common/common/bin/dfwhealthtestctl.sh
./oracle_common/common/bin/was_config.sh
./oracle_common/common/bin/dfwhealthtestadminctl.sh
./oracle_common/common/bin/dfwhealthtestcommon.sh
./oracle_common/jdk/db/bin/derby_common.sh
./oracle_common/oui/bin/runSSHSetup.sh
./wlserver_10.3/common/bin/config.sh
./wlserver_10.3/common/bin/pack.sh
./wlserver_10.3/common/bin/upgrade.sh
./wlserver_10.3/common/bin/config_builder.sh
./wlserver_10.3/common/bin/wlst.sh
./wlserver_10.3/common/bin/wlscontrol.sh
./wlserver_10.3/common/bin/commEnv.sh
./wlserver_10.3/common/bin/unpack.sh
./wlserver_10.3/common/bin/startManagedWebLogic.sh
./wlserver_10.3/common/derby/bin/derby_common.sh
./wlserver_10.3/server/bin/setWLSEnv.sh
./wlserver_10.3/server/bin/startNodeManager.sh
./wlserver_10.3/server/lib/unix/nodemanager.sh
./user_projects/domains/FormsDomain/bin/nodemanager/wlscontrol.sh
./user_projects/domains/FormsDomain/bin/secureWebLogic.sh
./user_projects/domains/FormsDomain/bin/stopWebLogic.sh
./user_projects/domains/FormsDomain/bin/startWebLogic.sh
./user_projects/domains/FormsDomain/bin/setDomainEnv.sh
[forms@solaris middleware]$
Avatar of Jason Yu
Jason Yu
Flag of United States of America image

ASKER

all files are under $MW_HOME which is /u2/oracle/middleware
Avatar of woolmilkporc
for file in $(find $MW_HOME -type f -name "*.sh" -exec grep -il JAVA_HOME {} \;)
   do
     sed -i.bak 's@JAVA_HOME="/usr/java/jdk1.6.0_18"@JAVA_HOME="/usr/java/jdk1.7.0_45"@' $file
   done

The above will ceate a backup of each file (by appending ".bak") andthen change each file in place.
Could you please explain a little bit of the "sed" line?

Also, do I need put these three four lines in a script and execute it?
Can I also add a log file to this script so that I can check the result?

thanks.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So you don't  have to go through this again when you update Java, I suggest you change it to:
 JAVA_HOME="/usr/java/latest"

/usr/java/latest is a link to the latest Java package installed, and gets relinked whenever you update Java
Good point, given that the "latest" version is indeed desired!
Dear experts, thank you two for quick responds, I really appreciate your help.

I will run the script as you suggested.

tfewster;

For this case, I just can't use the symbolic link. As it was explained in oracle article (Doc ID 1309855.1):




SOLUTION

Alternatives

There are two different approaches that can be used to achieve the required goal. Both will be described briefly:

A) Installing a new JDK home, and then renaming the existing JDK directory

Please avoid using symlinks as previously suggested in this note, as tools such as T2P (test to production) do require a FULL JDK directory structure, and might fail if a symbolic link is used.

Following this approach, the JDK directory location originally used during the installation will not change , and hence it has the minimal drawback that it might keep a versioned name as for example "$INSTALL_HOME/jdk_<version>" while in truth it contains a new version. You may need to follow the next approach once to edit direcories to a generic name, but then able to update regularly by swapping out the contents of the jdk directory. (See the "Tips" in Note 1492980.1)


B) Installing a new JDK home directory and replacing the JAVA_HOME environmental variable in *** all *** the scripts referring to it.

This is the preferred approach if you want to do a partial upgrade (affecting to specific domains only, or not affecting to nodemanager), but its difficulty is around on how to know which files do refer to a JDK location.

The initial list of files to change will be :

* $INSTALL_HOME/wlserver_10.3/common/bin/commEnv.sh
* $INSTALL_HOME/user_projects/domains/<mydomain>/bin/setDomainEnv.sh
* $INSTALL_HOME/wlserver_10.3/common/nodemanager/nodemanager.properties
* $INSTALL_HOME/utils/bsu/bsu.sh
* $INSTALL_HOME/utils/quickstart/quickstart.sh
* $INSTALL_HOME/utils/uninstall/uninstall.sh
even that a more exhaustive way to determine them, will be to run the following command:

find . -type f -name "*.sh" -exec grep -il JAVA_HOME {} \;
Step by Step Actions
Wonderful, I got the script running successfully.  does the return code "0" mean it's successful?


------- Mon Sep 22 13:52:31 PDT 2014 -------
Now working on --- /u2/oracle/middleware/utils/clone/clone.sh ---
Processed --- /u2/oracle/middleware/utils/clone/clone.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/utils/clone/restore.sh ---
Processed --- /u2/oracle/middleware/utils/clone/restore.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/utils/uninstall/uninstall.sh ---
Processed --- /u2/oracle/middleware/utils/uninstall/uninstall.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/utils/bsu/bsu.sh ---
Processed --- /u2/oracle/middleware/utils/bsu/bsu.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/utils/quickstart/quickstart.sh ---
Processed --- /u2/oracle/middleware/utils/quickstart/quickstart.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/FormsHome/bin/runProvisioningAntTasks.sh ---
Processed --- /u2/oracle/middleware/FormsHome/bin/runProvisioningAntTasks.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/FormsHome/sqldeveloper/ide/bin/launcher.sh ---
Processed --- /u2/oracle/middleware/FormsHome/sqldeveloper/ide/bin/launcher.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/FormsHome/oui/bin/runSSHSetup.sh ---
Processed --- /u2/oracle/middleware/FormsHome/oui/bin/runSSHSetup.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/oracle_common/sysman/deploy/agentdeploy/remoteif/resources/scripts/sshConnectivity.sh ---
Processed --- /u2/oracle/middleware/oracle_common/sysman/deploy/agentdeploy/remoteif/resources/scripts/sshConnectivity.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/oracle_common/modules/oracle.ovd_11.1.1/oimtemplates/extendadschema.sh ---
Processed --- /u2/oracle/middleware/oracle_common/modules/oracle.ovd_11.1.1/oimtemplates/extendadschema.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/oracle_common/bin/SSLGenCA.sh ---
Processed --- /u2/oracle/middleware/oracle_common/bin/SSLGenCA.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/oracle_common/bin/WLS_SSL_Client_Config.sh ---
Processed --- /u2/oracle/middleware/oracle_common/bin/WLS_SSL_Client_Config.sh --- with returncode 0
Now working on --- /u2/oracle/middleware/oracle_common/bin/pasteConfig.sh ---
Processed --- /u2/oracle/middleware/oracle_common/bin/pasteConfig.sh --- with re
Yes, returncode 0 means "OK". Congrats!
woolmilkporc is best, his quick solution helped me achieve an important milestone.