Chapter 8. Administration with scripting 345
4. If the job runs and finds that the application is not installed, the application is then
installed. If the application is already installed, it is uninstalled and then re-installed.
5. The text file is renamed filename.txt.old when the job is executed.
6. If the job executes and no text file exists, no actions are taken. It is only when you
distribute a new text file and application that the job performs the install.
To test, we used the following applications:
hello1.ear
hello2.ear
8.8.2 Creating the customized script
The AdminApplication script in the script libraries includes procedures that accomplish the
installation and update of applications. In this scenario, we used the following procedures
from the script libraries:
AdminApplication.uninstallApplication
This procedure is used to uninstall an application. The arguments specify the application
name.
AdminApplication.installAppWithNodeAndServerOptions
This procedure is used to install an application. This procedure is selected because there
is only a single server in this environment. In an environment with clustered application
servers, use the installAppWithClusterOption procedure instead.
The script file is written in Python and is called appInstall.py (see Example 8-28).
Example 8-28 The appInstall.py script
#Check the list and install/update the applications.
#
import sys
import java
import os
import re
import time
from java.lang import *
dir = "C:/WebSphereV8.5/AppServer/profiles/dmgr40/downloadedContent/inputfile"
#
sep = System.getProperty("line.separator")
for fname in os.listdir(dir):
print fname
path = os.path.join(dir, fname)
if (os.path.isfile(path)) and (not re.match(".*old$",path) and (not
re.match("appInstall.py",fname))):
print "procesing %s" % (path)
inp = open(path, 'r')
for line in inp.readlines():
itemList = line[:-1].split(',')
appName = itemList[0]
earFile = itemList[1]
nodeName= itemList[2]