Solved

how could I change JAVA_HOME in all these files

Posted on 2014-09-22
11
516 Views
Last Modified: 2014-09-22
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]$
0
Comment
Question by:Jason Yu
  • 6
  • 4
11 Comments
 

Author Comment

by:Jason Yu
Comment Utility
all files are under $MW_HOME which is /u2/oracle/middleware
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
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.
0
 

Author Comment

by:Jason Yu
Comment Utility
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?
0
 

Author Comment

by:Jason Yu
Comment Utility
Can I also add a log file to this script so that I can check the result?

thanks.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
Yep.

The "-i" flag tells "sed" to change the file "in place". If "-i" is immediately followed by some string then "sed" will create backup files using that string as a suffix.

The stuff between the quotes is the script to be interpreted by "sed". I used single quotes because there are double quotes in your patterns.

"s" is the subcommand ("subsitute") for replacing strings by other ones.

"@" is the field separator. I used it instead of the usual "/" because there are slashes in your patterns.

The string between the first and second separators is the one to be searched and replaced, and the string between the second and third separators is the one to replace the first string.

$file is the variable filled by the "for" loop with the results of the "find" command, one by one.

You should indeed create a file, maybe in your HOME directory or somewhere else, but not inside the directory structure you're working on (It might be that you choose the script's name as "something.sh", and the script obviously contains the search strings of "grep" and "sed"!) This file should contain the code I posted.
Execute the script either with

sh /path/to/script.sh

or with

chmod +x /path/to/script.sh
/path/to/script.sh

"sed -i" normally does not write any output to the terminal or to a log. We could write our own log, perhaps like this:

LOG=/tmp/mylog
echo "------- $(date) -------" > $LOG
for file in $(find $MW_HOME -type f -name "*.sh" -exec grep -il JAVA_HOME {} \;)
   do
     echo "Now working on --- $file ---"
     sed -i.bak 's@JAVA_HOME="/usr/java/jdk1.6.0_18"@JAVA_HOME="/usr/java/jdk1.7.0_45"@' $file
     echo "Processed      --- $file --- with returncode $?"
   done >>$LOG 2>&1

I added "2>&1" to also redirect possible error messages to the new log, not just our own "echos".
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
Good point, given that the "latest" version is indeed desired!
0
 

Author Comment

by:Jason Yu
Comment Utility
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
0
 

Author Comment

by:Jason Yu
Comment Utility
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
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
Yes, returncode 0 means "OK". Congrats!
0
 

Author Closing Comment

by:Jason Yu
Comment Utility
woolmilkporc is best, his quick solution helped me achieve an important milestone.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now