Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

jyhton scripts to check for application

Below is the Jython script to check if the application exists on server.

import java
import sys
import java
import ConfigParser
import time
import glob
import os
from java.util import Properties

global AdminConfig
global AdminControl
global AdminApp
global AdminTask

installedapps = AdminApp.list().splitlines()
print installedapps
      if ivtApp in installedapps:
            print 'app exists'
                  
            else:
            print 'app does not exists'
            
            
################################################################

The output for       
print installedapps       is

 ['DefaultApplication', 'PlantsByWebSphere', 'SamplesGallery', 'ivtApp', 'query']


I am running the script as

C:\Program Files\IBM\WebSphere\AppServer\bin>wsadmin.bat -f check_application.py
 -lang jython -user username -password mypassword

#########################################################################
The error :

WASX7017E: Exception received while running file "check_application.py"; excepti
on information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  (no code object) at line 0
  File "<string>", line 58
                if "ivtApp" in installedapps:
                ^
SyntaxError: invalid syntax
0
gaurav sharma
Asked:
gaurav sharma
  • 3
  • 2
2 Solutions
 
Pasha KravtsovSupport EngineerCommented:
You had improper indentation,
Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.
import java
import sys
import java
import ConfigParser
import time
import glob
import os
from java.util import Properties

global AdminConfig
global AdminControl
global AdminApp
global AdminTask

installedapps = AdminApp.list().splitlines()
print installedapps
if ivtApp in installedapps:
	print 'app exists'
else:
	print 'app does not exists'

Open in new window

0
 
gaurav sharmaAuthor Commented:
Ok ..used the above script ...Now I get the error

WASX7017E: Exception received while running file "check_application.py"; excepti
on information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 17, in ?
NameError: ivtApp
0
 
Pasha KravtsovSupport EngineerCommented:
That's because
if ivtApp in installedapps:

Open in new window

ivtApp doesn't exist. You need to assign it something for example the installed application you're looking for.
ivtApp = "your_app_you_are_looking_for"

Open in new window

Maybe you should read a simple python tutorial?
0
 
gaurav sharmaAuthor Commented:
Thanks ..that solved the problem. I am completely new to python and jython programming. Can you suggest some good materials ?
0
 
Pasha KravtsovSupport EngineerCommented:
No problem! And of course, here is an EE one:
http://www.experts-exchange.com/VP_47.html
I personally haven't watched it but it looks like from the comments and rating that it's a good start
The documentation provided for python & jython have always been my best learning source also:
https://wiki.python.org/jython/LearningJython
http://jython.org/docs/tutorial/indexprogress.html
http://www.jython.org/jythonbook/en/1.0/LangSyntax.html
And here is a beginner friendly one :)
http://www.javalobby.org/articles/jython/
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now