UNIX‎ > ‎

Kishore Scripts


Terminating WebLogic instance

UNIX command set for stop instances from a common location of a machine

In a development environment that consists of too many UNIX users. Each developers may have one or more WebLogic server instances for their application related System Testing. There is a need of restarting the server frequently. This task can be in two step process:

  1. Identify the weblogic instance process id

  2. Terminating the process

Identifying WebLogic instance

To stop the WebLogic instance they need to identify the process id that is initiated by this user using $LOGNAME.
ps -fu $LOGNAME
Now we need to filter the process list that initiated by Java command.
ps -fu $LOGNAME|grep java

The ppid can be collected into a variable by awk or nawk command line that extract second column.
PID=`more temp2|awk '{print $2}'`

Terminating process

And that PID can be the argument for the 'kill' command for terminate the instance .

Kill command can be given in two ways:

1.Graceful Kill

kill -15 pid
2. Forceful Kill: The terminal signal -9 indicates force stopping the process tree.
kill -9 $PID
Now the server has been stopped by kill command. To ensure that the java process exists in the process list or not.
Finally the completed script would be like this
  1. #!/bin/bash

  2. # This script is used to kill the WebLogic server instance

  3. # Author: PCHN KISHORE

  4. # Dated: 30-09-2010

  5. # Updated : 2/21/2012

  6. PID==`ps -fu $LOGNAME |grep java |grep -v grep|nawk '{print $2}'`

  7. if [ $PID ]

  8. then

  9. kill -9 $PID

  10. echo 'confirming...'

  11. ps -fu $LOGNAME

  12. else

  13. echo "Server is already stopped"

  14. fi

Note: This script will terminate only java processes.

Change Database for WebLogic

This is a different war game, here is a shell script that makes developers team happy!! In a day there could be multiple times DB changes from one schema to other. Instead of going to WebLogic admin console, you can simply run this script it will automatically changes the required things in the Configuration file which is not really recommended way.


Here the major challenges for building this script are:

  1. Datasources can be simple standalone datasource or multi-datasource.

  2. User might entered wrong DB details

  3. The datasource targeted to

  • Non-clustered (single instance)

  • Clustered

  1. WebLogic Database “config.xml” allows only Encrypted password

The dbping Utility

The second challenge listed user may enter unknowingly wrong DB details then there is no need of changing configuration file. Here is the need of the validation of the given DB details, this can be perormed with WebLogic provided command utility dbping.


WebLogic given another powerful utility for security encryption purpose: weblogic.security.Encrypt

java weblogic.security.Encrypt <passwd>

The result can be stored into a variable for further refered in the script.

The SED Tricks

The new Database schema details can be replaced with the configuration repository with “sed” command for ex:

grep "jdbc/" /export/home/domains/wd$LOGNAME/config/config.xml|cut -d "/" -f 2-2|cut -d "<" -f 1-1|grep -v "MDS">$DOMAINDIR/dsfilenames

The above command moves all datasouce file names into a file dsfilenames.

MDS means multidatasource name. We need not change MDS file for pointing the datasouce to new database schema we only modify the datasouce files in the folder


for i in $(more dsfilenames)
sed "s/<url>.*<\/url>/<url>jdbc:oracle:thin:@$ipport:$schema<\/url>/g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i
sed "s/<value>.*<\/value>/<value>$username<\/value>/g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i
sed "s@<password-encrypted>.*<\/password-encrypted>@<password-encrypted>$ENCPASS<\/password-encrypted>@g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i

Regular expressions

This script used lots of regular expressions.

Finally please refer the attached complete script for changing the database schema.


Apr 21, 2012, 11:53 PM
Apr 21, 2012, 11:55 PM