Shell script to find weblogic home directory

Hi,

I am trying to find the weblogic home directory whether it is installed in the Linux box. if it is existing display the weblogic home and the corresponding Java home directory else display message as that wl home does not exist. I already wrote a program but it was not working properly.
Please help me

#!/bin/ksh
WL_LOCATION=`find / -name wlserver_*`
if [-d $WL_LOCATION ] then
echo "WL_HOME ......... $WL_LOCATION"
cd $WL_LOCATION/common/bin
echo `pwd`
echo `sed s/\"//g grep JAVA_HOME commEnv.sh | grep jdk`
else echo "WL Home does not exists ...."
fi

Regards,
Spgreddy

---------- Post updated at 02:07 AM ---------- Previous update was at 12:21 AM ----------

Hi

I modified the script as shown below.

#!/bin/ksh
WL_LOCATION=`find / -name wlserver_*`
echo " $WL_LOCATION"
if [! -d $WL_LOCATION]; then
        echo "WL HOME does not exists ..." exit 1
        exit 1
else {
        echo "WL_HOME ......... $WL_LOCATION"
        cd $WL_LOCATION/common/bin
        echo `grep JAVA_HOME commEnv.sh | grep jdk|sed 's/"//g'`
      }
fi

when I execute, the below is the output.

/u01/app/oracle/Middleware/wlserver_10.3
./test1.sh[5]: [!: not found [No such file or directory]
WL_HOME ......... /u01/app/oracle/Middleware/wlserver_10.3
JAVA_HOME=/u01/app/jdk1.6.0_02

But here I am not able to understand that why it shows like this even it provides the actual output.

./test1.sh[5]: [!: not found [No such file or directory]

Please help us how to over come this?

There are several things that look strange in your script and I'm sure it isn't doing what you are trying to do. There are missing quotes, missing seicolons, extraneous echoes, unnecessary command substitutions, and I have no idea what the sed command is trying to do. But, since I don't know where weblogic might be installed on your server, I can't guess at what you are trying to do.

Is there a user named weblogic on your server?

After looking at every file on your system, are you sure that there will be exactly one file with a name starting with the characters wlserver_ ? Are there any constraints on where that one file could be located?

Please describe in English the logic behind each step in your script so we can help you modify your code to fix any problems you are running into.

Hi Don,

Thank you for your support. Forget above script currently I am looking a shell script by reading the string (/u01/app/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar) and display required output as shown below

/u01/app/oracle/Middleware/wlserver_10.3

Please help us to resolve this

Regards,
Spgreddy

I can't figure out what this means. Does the string you are reading contain parentheses as shown? Is this string in a file? Is this string in a shell variable?

How is your script supposed to know what part of the string is the part you want to return? Are you trying to remove the last three components of the pathname stored in the string? Are you trying to remove all components of the pathname after the component that starts with wlserver ? Are you trying to remove all components from the pathname stored in the string after the component that ends with a decimal digit? Are you trying to remove the 6th / and everything that follows it from your string?

What shell are you using? What OS are you using?

Hi DOn
The string contains /u01/app/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar

For example :

x=/u01/app/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar

i am trying to remove the last three componets /server/lib/weblogic.jar
and want to display the output as /u01/app/oracle/Middleware/wlserver_10.3

currently i am using bash sheel in redhat linux 5

Regards,
Spgreddy

So try something like:

#!/bin/bash
x=/u01/app/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar
y=${x%/*/*/*}
printf 'x is %s\ny is %s\n' "$x" "$y"

which produces:

x is /u01/app/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar
y is /u01/app/oracle/Middleware/wlserver_10.3
1 Like

Hi Don,

I have one more issue. A variable contains value like this

jhome=JAVA_HOME=/u01/app/jdk1.6.0_02
 

now I want output as

jhome=/u01/app/jdk1.6.0_02

please help me how can I write shell script for this

Regards,
Spgreddy

You need to be much more descriptive about what you are trying to do. One simple way to do what you have requested is:

echo 'jhome=/u01/app/jdk1.6.0_02'

If you are trying to modify some input that follows a certain format into a different output format, explain what your input format is and the changes to be performed to produce the output format that you want.

Hi Don,

The input format is

jhome=JAVA_HOME=/u01/app/jdk1.6.0_02

output format which we require

echo 'jhome=/u01/app/jdk1.6.0_02'

Regards,
Spgreddy

The input and output you have specified are fixed strings; not formats. You have not specified what steps are to be taken to transform your input to your desired output.

A wild guess at your input format could be something like:

name1=name2=absolute_pathname

where name1 is a shell variable name consisting of only lowercase letters, name2 is a shell variable name consisting of only uppercase letters and underscore characters, and absolute_pathname is an absolute pathname containing three components in addition to the root directory and none of the components contain any whitespace characters but nay contain one or more periods (which are special in a regular expression).

Without knowing what your real input and output formats are and what transformations you are trying to perform, we can only waste our time guesing at what needs to be done to transform one fixed string into another fixed string unless we just suggest that you print the desired output string!

To get your new desired output, execute the command:

echo "echo 'jhome=/u01/app/jdk1.6.0_02'"

Hi Don,

Please find the scenario.

jhome=`grep JAVA_HOME commEnv.sh | grep jdk|sed 's/"//g'`

In the above code jhome is variable,JAVA_HOME is search pattern, commEnv.sh is file, jdk is another search pattern. When I executed the above command in the server it gives the output as

echo " jhome=$jhome"
jhome=JAVA_HOME=/u01/app/jdk1.6.0_02

mean jhome variable contains the value JAVA_HOME=/u01/app/jdk1.6.0_02.

Now my requirement is to extract /u01/app/jdk1.6.0_02 by truncating the JAVA_HOME=

so that the jhome variable value is /u01/app/jdk1.6.0_02.

Please help me how to solve this

Regards
Spgreddy

jhome=`grep JAVA_HOME commEnv.sh | grep jdk|sed 's/"//g;s/JAVA_HOME=//'`