Wednesday, August 4, 2010

WebLogic Port mapping to Process ID

Hey dear WLA most of us come from Development environment to production environments. Hope the scienario thatI am going to discuss here is a common to everyone, who is working on development environment. Sometime or other you might felt I should have a handy script that could takes input as a WebLogic instance port which usually get from the applicaiton URL. The WebLogic port and list all the Process IDs which are associated with it on UNIX(here I got solution for Solaris) environment. Recently I found a Sun blog which is clearly discussed similar issue. I am re-compiling the same with customizing to our WebLogic Listen Port, WebLogic Server runs with a Java generated child Process ID. 'lsof' is the command you can execute and get this solved but most of the times it is a Sun third party downloads, that is not allowed in many Banking, Financial and Insurance Service organizations. And one more reason is small companies doesn't efford for third party tools.

Then, Your choice will be writing a handy script that will do the same task as lsof command helps to find the process id for a given WebLogic Listening port.
#!/bin/ksh 
 
pids=$(/usr/bin/ps -ef -o pid=)
 
if [ $# -eq 0 ]; then 
   read wlport?"Enter port you would like to know Java Process Id for: " 
else 
   wlport=$1 
fi 
 
for f in $pids 
do 
   /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $wlport$" 
   if [ $? -eq 0 ]; then 
        echo "===============***=============***==============="
        echo "ListenPort: $wlport is being used by Java PID:\c" 
        ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f 
        exit 0 # if you suspect more Weblogic instances with same listen port remove this
   fi 
done

Note: Save this script to commonly accessing user location name it as WLPort2Pid.ksh
Run with argument or without also it will work!! But you need to input the listening port that is must.
-->

Writing about this experiment is a new learning for me too.
Hope you enjoyed this one!! HAPPY SCRIPTING!!

8 comments:

  1. awesome script Pavan, will definitely come handy for new wls admins :)

    ReplyDelete
  2. where is the script? Is it missing or am I the stupidest person in the world?

    ReplyDelete
  3. uhh.. seems its missing..

    ReplyDelete
  4. It was link from pastebin.com due that site unavailability it might be not visible for some time. Now I pasted directly google highlighter, hope you get it now. Thanks for notifying me.

    ReplyDelete
  5. This would be helpful for getting the pid

    jps -v | grep "managed_server_name" | cut -f1 -d' '

    ReplyDelete
  6. Thank you for posting script for weblogic port mapping to process id.
    Regards,
    WebLogic training in Hyderabad.

    ReplyDelete
  7. Nice and Great information you have shared,Thanks For sharing to us.server traning

    ReplyDelete
  8. Thanks for sharing information, excellent article, keep continue this....

    python training in chennai

    python training in chennai

    ReplyDelete

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6