Friday, October 2, 2015

Invoking Jython script for wsadmin

Once you have installed WebSphere you have Jython shell built in available.

Logon profile editing for environment variables

In Linux bash shell is default login shell. Hence we can edit the .bash_profile or .bashrc file to get the user defined environment variables. We can define the alias for lengthy repeated tasks as shortcuts with simple shorten words.

Here I have my environment setup from .bash_profile

clear
echo "Welcome to WebSphere 8.5.5.6"
export PROFILE_HOME="/home/vagrant/IBM/WebSphere/AppServer/profiles"
export WAS_HOME=/home/vagrant/IBM/WebSphere/AppServer

alias wsadmin="cd /home/vagrant/IBM/WebSphere/AppServer/profiles/rplan-profile/bin/; . wsadmin.sh -lang jython"
alias ll="ls -lahtr"
alias cls="clear"
alias dmgrbin="cd ${WAS_HOME}/profiles/rplan-profile/bin; ls -lrth"
alias nodebin="cd ${WAS_HOME}/IBM/WebSphere/AppServer/profiles/rplan-profile"

Invoking your wsadmin for Jython made simple with alias at the command line you can simply use wsadmin it will navigate to the profile/bin directory then execute the wsadmin.sh script with the lang option jython.

vagrant@ubuntu-was8:~$ wsadmin
dirname: invalid option -- 'b'
Try 'dirname --help' for more information.
-bash: /setupCmdLine.sh: No such file or directory
WASX7209I: Connected to process "server1" on node ubuntu-was8Node01 using SOAP connector;  The type of process is: UnManagedProcess
WASX7031I: For help, enter: "print Help.help()"
wsadmin>

Interactive mode wsadmin

Trail and error we can do mostly at the interactive mode wsadmin shell. When we get the results as expected then we can collect all of those statement to form the script.
wsadmin>print "Hello Jython World"
Hello Jython World
wsadmin>print 10+20*2/5
18
wsadmin>import sys
wsadmin>sys.stdout.write('Jython is powerful automation tool\n')
Jython is powerful automation tool

The above connection default to SOAP based it will be taking the connection parameters from the profile that is available to it.

Connect in local mode

When you use the -conntype NONE
vagrant@ubuntu-was8:~$ wsadmin -conntype NONE
dirname: invalid option -- 'b'
Try 'dirname --help' for more information.
-bash: /setupCmdLine.sh: No such file or directory
WASX7357I: By request, this scripting client is not connected to any server process. Certain configuration and application operations will be available in local mode.
WASX7031I: For help, enter: "print Help.help()"
wsadmin>

Script mode wsadmin

Script mode is that where you can make simple blocks of code into program structure.
# This is first Jython script

print "Hey this is first Jython script"
print "you can use single quotes, double quotes'"
ml="""
 multiple
 new line
 another line
"""
print ml


To run the script mode you need to use the -f option then the python file path in the command line.
vagrant@ubuntu-was8:~$ wsadmin -f /home/vagrant/scripts/first.py
dirname: invalid option -- 'b'
Try 'dirname --help' for more information.

Hey this is first Jython script
you can use single quotes, double quotes'

 multiple
 new line
 another line

wsadmin>


No comments:

Post a Comment

Containerization with Docker

Containerization with Docker
Learn modern microservices containers grow