Solved

WAS7 automation scripts

Posted on 2012-03-16
7
466 Views
Last Modified: 2012-03-19
like that i have 20 apps
so now i am running each application using below command at command prompt manually:
wsadmin.bat -lang jython -f C:/opt/WAS/xxxx/deployments/scripts/createJ2Cauth.py C:/opt/WAS/xxxx/deployments/scripts/apps/yyyy/app1/createj2cauth.properties
............
in my development environment it is working fine
Now my questions is:
1) i need a shell script or jython script to run and set all resources(like batch file) on UNIX and windows environment
2) i need a shell script or jython script to run particular .py and .properties to set resource by taking the user input.
Ex: i need to update only J2C authentications
i am not expert in shell or jython script could you please somebody help me on this ...

Thanks in advance
0
Comment
Question by:prathapjava
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 37730908
You have lots of options.
For example:
- if all of the commands to be executed are in some directory, and they all use the same properties file, you could have a Jython script expect / require the "directory" containing the scripts to be executed.  It could then use operating systems command to identify all of the *.py (or *.jy) files in the specified directory, and use "execfile" command to execute each.
> The challenges:
  ? What should be done if & when an error is encountered?

- Another possibility: have a file contain the list of script to be executed.
  This has the advantage of specifying an order in which the scripts should be run.

What would you like to do?
0
 

Author Comment

by:prathapjava
ID: 37731078
we have 20 applications  folder structure like below:
each application i created below WAS scripts to configures resources in WAS7:
C:\opt\WAS\xxxxx\deployments\scripts\createdatasource.py
C:\opt\WAS\xxxxx\deployments\scripts\deployear.py
C:\opt\WAS\xxxxx\deployments\scripts\createtimermanager.py
C:\opt\WAS\xxxxx\deployments\scripts\createJ2CAuth.py
C:\opt\WAS\xxxxx\deployments\scripts\createworkmanager.py

each application properties we have separate properties file directories like below
app1:
C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyy\app1\createdatasource.properties
C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyy\app1\deployear.propetties
C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyy\app1\createtimermanager.properties
C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyys\app1\createJ2CAuth.properties
C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyy\app1\createworkmanager.properties
app2:
................................................
............................................
..................................................
like that i have 20 apps
so now i am running each application using below command at command prompt manually:
wsadmin.bat -lang jython -f C:/opt/WAS/xxxx/deployments/scripts/createJ2Cauth.py C:/opt/WAS/xxxx/deployments/scripts/apps/yyyy/app1/createj2cauth.properties
............
in my development environment it is working fine
Now my questions is:
1) i need a shell script or jython script to run and set all resources(like batch file) on UNIX and windows environment
2) i need a shell script or jython script to run particular .py and .properties to set resource by taking the user input.
Ex: i need to update only J2C authentications
i am not expert in shell or jython script could you please somebody help me on this ...

Thanks in advance
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 37732601
Much of which just said was stated when you opened the question.

Q: Do each of the scripts to configures resources, i.e., the ones in this folder:

     C:\opt\WAS\xxxxx\deployments\scripts

     each contain a single (or small number) of function definitions?
     or, do the each contain a bunch of code?

Can you attach one, or a small number, so that we can get an idea what they look like?
If you can, please include the corresponding properties file so that we can better understand how the scripts work.

Would you prefer 1 script that allows you to specify command line options identifying the operation to be performed?

For example, something like:

wsadmin -lang jython -f configure.py --application AppName --operation createJ2Cauth

Open in new window


If the directories containing the function to be executed, and the properties files are fixed, then this could be "hard coded" in the "configure.py" script.

Does that make sense?

Of course this is just one, of many possible, options.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:prathapjava
ID: 37733398
As you mentioned please find the attached createJ2C.py and create j2c.properties files

now i am running particular .py file using the command below in windows command prompt its working fine:
wsadmin.bat -lang jython -f C:/opt/WAS/xxxxx/deployments/scripts/createJ2Cauth.py C:\opt\WAS\xxxxx\deployments\scripts\apps\yyyys\app1\createJ2CAuth.properties

here j2c for one application app1 is working fine but i have app1,app2,app3...........app20 like 20applicatication i need shell or jython script to run all apps at a time and also i need another script in that user can input app name command line  arguments like
app3 j2c update/create then the script should able to call particular .py and respective .properties file this is my requirement

sorry for the confusion i think now you got my question

thanks in advance
createJ2CAuth.py
createj2cauth.txt
0
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 37737372
- One interesting technique that is used by the script (createJ2CAuth.py), is the way that information is stored, and loaded from the properties file.  The code requires the properties file to be formatted in a specific way.

Q: Is this something that you came up with, or was it from someone / somewhere else?

- The reason I ask is that using "eval" to interpret the information from the properties file can be problematic. There are many examples of just how bad this technique can be, consider a properties file containing something like this:

  os.system( 'echo some nasty command' )

  As long as the os module has been imported, the result of using eval() to to "interpret" this would result in the execution of the command by the operating system.

- Ignoring that, for the moment, we can do what you want by adding a little something to the bottom of each of your *.py files.

- Currently, the script ends with code like this:
# Read command line arguments
# Please pass the updatedatasource.properties as command line argument
# /opt/WAS/stage/AppServer/bin/wsadmin.sh -lang jython -f createJ2CAuth.py createj2cauth.properties
if len(sys.argv) == 0:
    print "This script requires properties file as command line argument"
    exit(0)
else:
    infileName = sys.argv[0]
    exemain()

Open in new window


It we were to change the script just a little, it would prove very helpful, and beneficial to the task.

What should we do?

- Allow the script to be executed, or imported

While I was at it, I cleaned up the code a little.
1. I replaced all tab characters with spaces - mixing tabs and spaces to indent is a very bad practice
2. I passed parameters instead of depending upon global variable, e.g., exemain()
3. Changed readFile() to require a fileName, instead of fileHandle & dictionary

How does that help us solve the original problem?

Well, now this script can either be used stand-alone, just like is currently being used, and, it can also be imported by another script so that the createJ2CAlias() routine can be used elsewhere.  For example:

from createJ2CAuth_01 import createJ2CAlias

Open in new window


Does this make sense?

Then, you can have one script that allows you to decide what operation(s) you need to perform, and call the appropriate routine.
createJ2CAuth-01.py
0
 

Author Closing Comment

by:prathapjava
ID: 37738398
Thanks sir its working fine
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 37738514
Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now