WebSphere Application Server Network Deployment, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Listing running applications on running servers using scripting

Before you begin

Before starting this task, the wsadmin tool must be running. See the Starting the wsadmin scripting client article for more information.

Why and when to perform this task

Use the following example to list all the running applications on all the running servers on each node of each cell:
  • Using Jacl:
    *Provide this example as a Jacl script file and run it with  the "-f" option:
    1  #----------------------------------------------------------------
    2  # lines 4 and 5 find all the cell and process them one at a time
    3  #----------------------------------------------------------------
    4  set cells [$AdminConfig list Cell]
    5  foreach cell $cells {
    6     #-----------------------------------------------------------------------
    7     # lines 10 and 11 find all the nodes belonging to the cell and 
    8     # process them at a time
    9     #-----------------------------------------------------------------------
    10    set nodes [$AdminConfig list Node $cell]
    11    foreach node $nodes {
    12       #--------------------------------------------------------------
    13       # lines 16-20 find all the running servers belonging to the cell 
    14       # and node, and process them one at a time
    15       #--------------------------------------------------------------
    16       set cname [$AdminConfig showAttribute $cell name]
    17       set nname [$AdminConfig showAttribute $node name]
    18       set servs [$AdminControl queryNames type=Server,cell=$cname,node=$nname,*]
    19       puts "Number of running servers on node $nname: [llength $servs]"
    20       foreach server $servs {
    21           #---------------------------------------------------------
    22           # lines 25-31 get some attributes from the server to display; 
    23           # invoke an operation on the server JVM to display a property.  
    24           #---------------------------------------------------------
    25           set sname [$AdminControl getAttribute $server name]
    26           set ptype [$AdminControl getAttribute $server processType]
    27           set pid   [$AdminControl getAttribute $server pid]
    28           set state [$AdminControl getAttribute $server state]
    29           set jvm [$AdminControl queryNames type=JVM,cell=$cname,
    								node=$nname,process=$sname,*]
    30           set osname [$AdminControl invoke $jvm getProperty os.name]
    31           puts "  $sname ($ptype) has pid $pid; state: $state; on $osname"
    32
    j3           #---------------------------------------------------------
    34           # line 37-42 find the applications running on this server and 
    35           # display the application name. 
    35           #---------------------------------------------------------
    37           set apps [$AdminControl queryNames type=Application,
    								cell=$cname,node=$nname,process=$sname,*]
    38           puts "  Number of applications running on $sname: [llength $apps]"
    39           foreach app $apps {
    40              set aname [$AdminControl getAttribute $app name]
    41              puts "    $aname" 
    42           }
    43           puts "----------------------------------------------------"  
    44           puts ""
    45
    46        } 
    47     }
    48  }
    
  • Using Jython:
    * Provide this example as a Jython script file and run it with the "-f" option:
    
    1   #----------------------------------------------------------------
    2   # lines 7 and 8 find all the cell and process them one at a time
    3   #----------------------------------------------------------------
    4   # get line separator 
    5   import  java.lang.System  as  sys
    6   lineSeparator = sys.getProperty('line.separator')
    7   cells = AdminConfig.list('Cell').split(lineSeparator)
    8   for cell in cells:
    9        #----------------------------------------------------------------
    10      # lines 13 and 14 find all the nodes belonging to the cell and 
    11      # process them at a time
    12      #-----------------------------------------------------------------
    13      nodes = AdminConfig.list('Node', cell).split(lineSeparator)
    14      for node in nodes:
    15         #--------------------------------------------------------------
    16         # lines 19-23 find all the running servers belonging to the cell 
    17         # and node, and process them one at a time
    18       	 #--------------------------------------------------------------
    19       	 cname = AdminConfig.showAttribute(cell, 'name')
    20       	 nname = AdminConfig.showAttribute(node, 'name')
    21       	 servs = AdminControl.queryNames('type=Server,cell=' + cname + 
    								',node=' + nname + ',*').split(lineSeparator)
    22       	 print "Number of running servers on node " + 
    								nname + ": %s \n" % (len(servs))
    23       	 for server in servs:
    24      	    #---------------------------------------------------------
    25      	    # lines 28-34 get some attributes from the server to display; 
    26      	    # invoke an operation on the server JVM to display a property.
    27      	    #---------------------------------------------------------
    28      	    sname = AdminControl.getAttribute(server, 'name')
    29      	    ptype = AdminControl.getAttribute(server, 'processType')
    30      	    pid   = AdminControl.getAttribute(server, 'pid')
    31      	    state = AdminControl.getAttribute(server, 'state')
    32       	    jvm = AdminControl.queryNames('type=JVM,cell=' +  
     							cname + ',node=' + nname + ',process=' + sname + ',*')
    33      	    osname = AdminControl.invoke(jvm, 'getProperty', 'os.name')
    34       	    print " " + sname + " " +  ptype + " has pid " + pid + 
    											"; state: " + state + "; on " +     
     											osname + "\n"
    35
    36       	    #---------------------------------------------------------
    37       	    # line 40-45 find the applications running on this server and 
    38      	    # display the application name. 
    39      	    #---------------------------------------------------------
    40      	    apps = AdminControl.queryNames('type=Application,cell=' + 
     						Cname + ',node=' + nname + ',process=' + sname + ',*').
    										split(lineSeparator)
    41      	    print "Number of applications running on " + sname + 
    										": %s \n" % (len(apps))
    42      	    for app in apps:
    43      	       aname = AdminControl.getAttribute(app, 'name')
    44      	       print aname + "\n"
    45     	    print "----------------------------------------------------"
    46     	    print "\n"
  • Example output:
    Number of running servers on node mynode: 2
    mynode (NodeAgent) has pid 3592; state: STARTED; on Windows 2000
    Number of applications running on mynode: 0
    ----------------------------------------------------
    
    server1 (ManagedProcess) has pid 3972; state: STARTED; on Windows 2000
    Number of applications running on server1: 0
    ----------------------------------------------------
    
    Number of running servers on node mynodeManager: 1
    dmgr (DeploymentManager) has pid 3308; state: STARTED; on Windows 2000
    Number of applications running on dmgr: 2
    adminconsole
    filetransfer
    ----------------------------------------------------
    



Related concepts
AdminConfig object for scripted administration
AdminControl object for scripted administration

Related reference
Commands for the AdminConfig object
Commands for the AdminControl object

Task topic    

Terms of Use | Feedback

Last updated: Mar 17, 2005 4:28:29 AM CST
http://publib.boulder.ibm.com/infocenter/ws60help/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/txml_listrunapp.html

© Copyright IBM Corporation 2004, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)