0

我是 Jython 脚本语言和 IBM WAS 的新手。我正在尝试编写一小段脚本,它将为我提供配置详细信息,例如已安装应用程序列表和 IBM WAS 8 已用端口列表。我一直在尝试执行脚本并在 .txt 文件中收集详细信息,但是输出为空白。

我的代码是:-

#----------------------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-----------------------------------------

我已将此代码保存在 sample_script.py 文件中,并通过转到 app_server_root/bin bin>wsadmin -lang jython -f path/to/your/jython/sample_script.py 来执行脚本

这将打印 - WASX7209I:使用 SOAP 连接器连接到节点 dbserverNode01 上的进程“server1”;进程的类型是:UnManagedProcess

但是没有返回预期的输出。高度赞赏响应。

4

1 回答 1

0

我认为问题出在以下声明中:

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

sys.argv[0]保存执行脚本的名称,而不是第一个命令行参数。如果您正在调用脚本并将服务器和节点名称作为参数传递,请将上面的行更改为:

ex2(sys.argv[1], sys.argv[2])
于 2013-06-27T14:34:50.120 回答