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: Connected to process "server1" on node dbserverNode01 using SOAP conn ector; プロセスのタイプ: 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 に答える