0
votes

I am a newbie to both Jython scripting language and IBM WAS. I am trying to write a small piece of script which will give me the configuration details like list of installed applications and list of used ports of IBM WAS 8. I have been trying to execute the script and collect the details in a .txt file but the output is blank.

My code is :-

#----------------------Code Starts---------------------
import sys
import string
import random

def ex2(serverName, nodeName):

   #--------------------------------------------------------------
   # set up globals
   #--------------------------------------------------------------
   global AdminConfig
   global AdminTask
   global AdminApp

   #--------------------------------------------------------------
   # do some sanity checking 
   #     -- do we have a node by this name? 
   #--------------------------------------------------------------
   node = AdminConfig.getid("/Node:" + nodeName + "/")
   print "ex1: checking for existence of node " + nodeName
   if len(node) == 0:
      print "ex2: Error -- node not found for name " + nodeName
      return

   #--------------------------------------------------------------
   #     -- is a server by this name already running on the node? 
   #--------------------------------------------------------------
   print "ex2: checking to see if server " + serverName + " is running on node " +     nodeName
   runningServer = AdminControl.completeObjectName("type=Server,node=" + nodeName +     ",process=" + serverName + ",*")
   if len(runningServer) == 0:
      print "ex2: Error -- Server " + serverName + " not running on node " + nodeName
      return 

   #--------------------------------------------------------------
   # List the installed application - WAS_12
   #--------------------------------------------------------------
   print "List the installed application"
   App_List = AdminApp.list()
   my_file = open('App_List.txt','w')
   my_file.write(App_List)
   my_file.close()

   #--------------------------------------------------------------
   # Find the configuration object 
   #--------------------------------------------------------------
   server = AdminConfig.getid("/Node:" + nodeName + "/Server:" + serverName + "/");

   #--------------------------------------------------------------
   # List the ports present - WAS_14
   #--------------------------------------------------------------
   print "List the ports"
   PORT_List = AdminConfig.list("NamedEndPoint",server)
   my_file = open('Port_list.txt','w')
   my_file.write(PORT_List)
   my_file.close()


#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------

if len(sys.argv) != 2:
   print "ex2: this script requires 2 parameters: server name, node name"
   print "e.g.:     ex2  server2 mynode" 
else:
   ex2(sys.argv[0], sys.argv[1])

#-----------------Code Ends-----------------------------------------

I have saved this code in a sample_script.py file and I am executing the script by going to app_server_root/bin bin>wsadmin -lang jython -f path/to/your/jython/sample_script.py

This prints - WASX7209I: Connected to process "server1" on node dbserverNode01 using SOAP conn ector; The type of process is: UnManagedProcess

But no expected output is returned. Response is highly appreciated.

1
Are you looking your output file (Port_list.txt) on server or your localhost? Maybe You're looking in wrong place?Łukasz Siwiński

1 Answers

0
votes

I think the issue is within this statement:

ex2(sys.argv[0], sys.argv[1])

sys.argv[0] holds the name of the executing script, not the first command line argument. If you are calling your script and passing the server and node names as arguments, change the above line to this:

ex2(sys.argv[1], sys.argv[2])