我是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 conn连接到节点dbserverNode01上的“server1”进程 埃克特;进程类型为:UnManagedProcess
但是没有返回预期的输出。 回应非常感谢。
答案 0 :(得分:0)
我认为这个问题在这个声明中:
ex2(sys.argv[0], sys.argv[1])
sys.argv[0]
包含执行脚本的名称,而不是第一个命令行参数。如果要调用脚本并将服务器和节点名称作为参数传递,请将上面的行更改为:
ex2(sys.argv[1], sys.argv[2])