jython script for list servers

i have a  WAS7.0.0.21 ND on a linux machine, i got below  script from the was_root/scriptLibraries/servers/V70/AdminServerManagement.py ,  so when i run this python script i get no output and it wsadmin tool just brings back to prompt, please help me what i need to do in order to get list of servers, why this script is not working, what else i need  to provide in order it to work

      # Set global constants
      import sys
      import java
      import AdminUtilities

      # Setting up Global Variable within this script
      bundleName = "com.ibm.ws.scripting.resources.scriptLibraryMessage"
      resourceBundle = AdminUtilities.getResourceBundle(bundleName)

      ## Example 1 List available servers with given server type and node ##
      def listServers(serverType="APPLICATION_SERVER", nodeName="abe12", failonerror=AdminUtilities._BLANK_):
          if (failonerror==AdminUtilities._BLANK_):
          msgPrefix = "listServers("+`serverType`+", "+`nodeName`+", "+`failonerror`+"): "

            # List servers
            print "---------------------------------------------------------------"
            print " AdminServerManagement:  List servers"
            print " Optional parameters: "
            print "         Server type:    "+serverType
            print "         Node name:      "+nodeName
            print " Usage: AdminServerManagement.listServers(\""+serverType+"\", \""+nodeName+"\") "
            print " Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided."
            print "---------------------------------------------------------------"
            print " "
            print " "
            # Construct optional parameters
            optionalParamList = []

            if (len(serverType) > 0):
                optionalParamList = ['-serverType', serverType]

            if (len(nodeName) > 0):
                # check if node exists
                node = AdminConfig.getid("/Node:" +nodeName+"/")
                if (len(node) == 0):
                   raise AttributeError(AdminUtilities._formatNLS(resourceBundle, "WASL6040E", ["nodeName", nodeName]))
                optionalParamList = optionalParamList + ['-nodeName', nodeName]
            optionalParamList = optionalParamList + ['-nodeName', nodeName]

            # List servers with specified server type
            servers = AdminTask.listServers(optionalParamList)

            # Convert Jython string to list
            servers = AdminUtilities.convertToList(servers)

            # Loop through each server in server list
            newservers = []
            for aServer in servers:
                # Obtain server and node names
                sname = aServer[0:aServer.find("(")]
                nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
                # Retrieve the server config id
                sid = AdminConfig.getid("/Node:"+nname+"/Server:"+sname)
                if (newservers.count(sid) <= 0):
                #AdminUtilities.infoNotice("Server: " + sid)
            return newservers
            typ, val, tb = sys.exc_info()
            if (typ==SystemExit):  raise SystemExit,`val`
            if (failonerror != AdminUtilities._TRUE_):
                print "Exception: %s %s " % (sys.exc_type, sys.exc_value)
                val = "%s %s" % (sys.exc_type, sys.exc_value)
                raise "ScriptLibraryException: ", `val`
                return -1
                return AdminUtilities.fail(msgPrefix+AdminUtilities.getExceptionText(typ, val, tb), failonerror)
Who is Participating?
HonorGodSoftware EngineerCommented:
The problem is related to how you are invoking wsadmin, and providing the information to be used.

If we ignore the sudo stuff, the call to wsadmin looks like this:

./wsadmin.sh -c " AdminServerManagement.listServers(\""+serverType+"\", \""+nodeName+"\") "

Where is the operating system supposed to get the value of "serverType" and "nodeName"?

What you need to do is provide these values in the call.  For example:

./wsadmin.sh -c "AdminServerManagement.listServers('APPLICATION_SERVER', 'myNode01' )"

that is, if you want to list the configuration IDs for all of the APPLICATION_SERVER objects configured for the node named "myNode01".

If  you want to list the configuration IDs for all of the servers, of every type, in your cell, you can use a call something like:

./wsadmin.sh -c "AdminServerManagement.listServers( '', '' )"

Note how empty strings had to be specified, AND that since we used double quotes to start and stop the "command" to be executed by wsadmin, that we used an open, close single quoted string for each of the two parameters.

The first parameter, i.e., serverType should be something like:


and the second parameter must be either an empty string (meaning all nodes in the cell), or the name of an existing node in your cell.

Does that help?
HonorGodSoftware EngineerCommented:
Q: What do you mean by the phrase "I got below  script from ..."?
  Did you copy the routine somewhere?
  I'll need to understand this in order to answer the "why didn't it work" question

- It is important to realize that the AdminServerManagement library is automatically provided to the wsadmin environment (unless, for some reason, you have removed the scriptLibraries directory).

  So, to "use" the routine, you only need call the method, using syntax similar to:
 AdminServerManagement:  List servers
 Optional parameters:
         Server type:
         Node name:
 Usage: AdminServerManagement.listServers("", "")
 Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are pro

Open in new window

By the way, the fact that the routine generates that big banner mean that I don't like it very much.

On the other hand, you don't indicate the kind of information that you want, or the format of how it should be displayed.

If, on the other hand, you only want to list the names of the application servers in your cell, you can do something simple like:

wsadmin>for node in AdminConfig.list( 'Node' ).splitlines() :
wsadmin>    nodeName = AdminConfig.showAttribute( node, 'name' )
wsadmin>    for server in AdminConfig.list( 'Server', node ).splitlines() :
wsadmin>        servName = AdminConfig.showAttribute( server, 'name' )
wsadmin>        print '  Node: %s\nServer: %s\n' % ( nodeName, servName )

Open in new window

wasmanAuthor Commented:
What do you mean by the phrase "I got below  script from ..."?
yes i planning to use the sample scripts that came with WAS installations,  just experimenting with them, (was_root/scriptLibraries/servers/V70/AdminServerManagement.py).

  Did you copy the routine somewhere?
what is routine, i didn't copied any thing except the script from the WAS7 sample scripts

i just want to make this script work for me, if you help me fix this script by telling me what is missing in it, it will be easier for me modify other sample scripts that came with WAS7,

please feel free to ask more question if you didn't understand my goal.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

HonorGodSoftware EngineerCommented:
Are you using a wsadmin interactive session, or do you specify a script file to be executed (i.e., by providing the "-f" command line option)?

Did you modify the script to provide this command parameter?


Where did that come from?

My AdminServerManagement.py has this as line 99:

def listServers(serverType="", nodeName="", failonerror=AdminUtilities._BLANK_):

Open in new window

wasmanAuthor Commented:
i am providing the script with -f option and yes i modified this value nodeNAme="abc12" and also the serverType="APPLICATION_SERVER", initially they are left blank in example script, for me this line is -->       def listServers(serverType="APPLICATION_SERVER", nodeName="abe12", failonerror=AdminUtilities._BLANK_): is on line number 13
HonorGodSoftware EngineerCommented:
You shouldn't be modifying the routine.

You should be specifying values when you call the routine, as I showed above...
wasmanAuthor Commented:
when don't provide anything also i get nothing, basically comes back to prompt

def listServers(serverType="", nodeName="", failonerror=AdminUtilities._BLANK_):

$ sudo -u webadmin ./wsadmin.sh -f ~/scripts/listservers.py
Realm/Cell Name: <default>
Username: xx31952
Password:                                                                                                                                                                WASX7209I: Connected to process "dmgr" on node abc12admgr using SOAP connector;  The type of process is: DeploymentManager
HonorGodSoftware EngineerCommented:
the way you should be calling it is:

$ sudo -u webadmin ./wsadmin.sh -c "AdminServerManagement.listServers()"

You have to realize though, that what you get back from this routine is an array / list of the configuration IDs of the configured application servers.

Which say "execute this command" (i.e., the command after the "-c")
The "-f", as you show, is used to execute a script.  If you want to, you could create a trivial script file to call this routine, and display more useful information from the results.  For example:

for server in AdminServerManagement.listServers() :
    Type = AdminConfig.showAttribute( server, 'serverType' )
    name = AdminConfig.showAttribute( server, 'name' )
    print 'ServerType:', Type
    print 'ServerName:', name

Open in new window

wasmanAuthor Commented:
that trivial script is working that was excellent, but can use the usage given in /opt/app/WebSphere7.0.0.21/AppServer/scriptLibraries/servers/V70/AdminServerManagement.py script which is

 Usage: AdminServerManagement.listServers(\""+serverType+"\", \""+nodeName+"\") "

so i used it now i get below error, can you please correct me with this

$ sudo -u webadmin ./wsadmin.sh -c " AdminServerManagement.listServers(\""+serverType+"\", \""+nodeName+"\") "
Realm/Cell Name: <default>
Username: webadmin
Password:                                                                                                                                                               WASX7209I: Connected to process "dmgr" on node lseth321admgr using SOAP connector;  The type of process is: DeploymentManager
 AdminServerManagement:  List servers
 Optional parameters:
         Server type:    +serverType+
         Node name:      +nodeName+
 Usage: AdminServerManagement.listServers("+serverType+", "+nodeName+")
 Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided.

Exception: exceptions.AttributeError WASL6040E: The nodeName:+nodeName+ specified argument does not exist.
WASX7015E: Exception running command: "AdminServerManagement.listServers("+serverType+", "+nodeName+")"; exception information:
 com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<input>", line 1, in ?
  File "/opt/app/WebSphere7.0.0.21/AppServer/scriptLibraries/servers/V70/AdminServerManagement.py", line 159, in listServers
ScriptLibraryException: : 'exceptions.AttributeError WASL6040E: The nodeName:+nodeName+ specified argument does not exist.'

wasmanAuthor Commented:
sure it helped, earlier i was trying without removing  special charactors, thank you HonorGod,
HonorGodSoftware EngineerCommented:
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.

If you are going to be doing much WebSphere Application Server administration using Jython, you may want to take a look at this book:

From IBM Press (publisher): http://www.ibmpressbooks.com/bookstore/product.asp?isbn=0137009526
From Amazon: http://www.amazon.com/dp/0137009526
wasmanAuthor Commented:
yeah i have that book, but didn't had enough time to learn jython.... i rarely get work on jython...on top i am not good at programming .... trying logic and syntaxs are my hard part, but thanks for advice
HonorGodSoftware EngineerCommented:
You are welcome.  If you have other questions, just ask.  We'll do what we can to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.