02-27-2014
Help needed with a shell script for deploying ear file to a weblogic server using WLST
Hi,
Please help me through a shell script to run from command prompt using WLST for the below purpose:
Automation process:
>Check the availability of an application.
>Stops the EAR if it already exists in Weblogic Server
>Undeploys/Delete the project (EAR file)
>Deploys the new ear file into the Weblogic Server
>Restart the services of the project (EAR)
By using the below command we can execute the shell script from command prompt through WLST:
>>java weblogic.WLST autodeploy.sh -u username -p password -a adminUrl [<hostname>:<port>] -n deploymentName -f deploymentFile -t deploymentTarget
I am attaching a python script which does the same but could you please provide the shell script in bash?
HTML Code:
#! /usr/bin/env python
import sys
import os
from java.lang import System
#Python Script to manage applications in weblogic server.
#This script takes input from command line and executes it.
#It can be used to check status,stop,start,deploy,undeploy of applications in weblogic server using weblogic wlst tool.
import getopt
#========================
#Usage Section
#========================
def usage():
print 'Usage:'
print 'java weblogic.WLST autodeploy.py -u username -p password -a adminUrl [<hostname>:<port>] -n deploymentName -f deploymentFile -t deploymentTarget\n';
sys.exit(2)
#========================
#Connect To Domain
#========================
def connectToDomain():
try:
connect(username, password, adminUrl)
print 'Successfully connected to the domain\n'
except:
print 'The domain is unreacheable. Please try again\n'
exit()
#========================
#Checking Application Status Section
#========================
def appstatus(deploymentName, deploymentTarget):
try:
cd('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
currentState = cmo.getCurrentState(deploymentName, deploymentTarget)
return currentState
except:
print 'Error in getting current status of ' +deploymentName+ '\n'
exit()
#========================
#Application undeployment Section
#========================
def undeployApplication():
try:
print 'stopping and undeploying ..' +deploymentName+ '\n'
stopApplication(deploymentName, targets=deploymentTarget)
undeploy(deploymentName, targets=deploymentTarget)
except:
print 'Error during the stop and undeployment of ' +deploymentName+ '\n'
#========================
#Applications deployment Section
#========================
def deployApplication():
try:
print 'Deploying the application ' +deploymentName+ '\n'
deploy(deploymentName,deploymentFile,targets=deploymentTarget)
startApplication(deploymentName)
except:
print 'Error during the deployment of ' +deploymentName+ '\n'
exit()
#========================
#Input Values Validation Section
#========================
if __name__=='__main__' or __name__== 'main':
try:
opts, args = getopt.getopt(sys.argv[1:], "u:p:a:n:f:t:", ["username=", "password=", "adminUrl=", "deploymentName=", "deploymentFile=", "deploymentTarget="])
except getopt.GetoptError, err:
print str(err)
usage()
username = ''
password = ''
adminUrl = ''
deploymentName = ''
deploymentFile = ''
deploymentTarget = ''
for opt, arg in opts:
if opt == "-u":
username = arg
elif opt == "-p":
password = arg
elif opt == "-a":
adminUrl = arg
elif opt == "-n":
deploymentName = arg
elif opt == "-f":
deploymentFile = arg
elif opt == "-t":
deploymentTarget = arg
if username == "":
print "Missing \"-u username\" parameter.\n"
usage()
elif password == "":
print "Missing \"-p password\" parameter.\n"
usage()
elif adminUrl == "":
print "Missing \"-a adminUrl\" parameter.\n"
usage()
elif deploymentName == "":
print "Missing \"-n deploymentName\" parameter.\n"
usage()
elif deploymentFile == "":
print "Missing \"-c deploymentFile\" parameter.\n"
usage()
elif deploymentTarget == "":
print "Missing \"-c deploymentTarget\" parameter.\n"
usage()
#========================
#Main Control Block For Operations
#========================
def deployUndeployMain():
try:
if appstatus(deploymentName, deploymentTarget)=='STATE_RETIRED' :
appflag=1
elif appstatus(deploymentName, deploymentTarget)=='STATE_ACTIVE':
appflag=2
else:
print ' other Applications are Running '
pass
if appflag == 1 :
print 'application having RETIERED STATE ..'
undeployApplication()
print appstatus(deploymentName, deploymentTarget)
deployApplication()
print appstatus(deploymentName, deploymentTarget)
elif appflag== 2:
print 'Application exists in ACTIVE state...'
undeployApplication()
deployApplication()
print appstatus(deploymentName, deploymentTarget)
else:
print 'new application'
deployApplication()
except:
print 'Error during the deployment of ' +deploymentName+ '\n'
exit()
#========================
#Execute Block
#========================
connectToDomain()
deployUndeployMain()
disconnect()
exit()
Thanks in Advance!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
HI,
I'm new in unix. I would like to know if you have a ready script for monitoring the weblogic and managed servers. I want to have a script that checks the weblogic once in a while if it's up and running. if not running, will send an email to me. any idea?
please help me. i will... (4 Replies)
Discussion started by: tungaw2004
4 Replies
2. Shell Programming and Scripting
Hi All,
I have a Sqlplus report which will create a file.
I need a FTP Script that will be executed inside the Sqlplus Report to FTP the report output file to unix server.
Thanks,
Previn (0 Replies)
Discussion started by: vprevin
0 Replies
3. Solaris
hi
This may not be right question to ask on this forum, but I think people here can answer the question.
Please give me details of steps/commands used in UNIX ( only command mode) for deploying an ear file on websphere.
Thanks in advance,
Ashish (2 Replies)
Discussion started by: ashish_uiit
2 Replies
4. Shell Programming and Scripting
Can I get the STATE(instance are RUNNING or not and HEALTH is OK or not) of the weblogic instances(Admin and Managed) running on my unix machine via shell script.
Someone told me that it can be done via "weblogic.Admin GETSTATE"....but it is not working for me(might be I am doing something wrong)... (2 Replies)
Discussion started by: joshilalit2004
2 Replies
5. Shell Programming and Scripting
This is the ldf file
dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com
objectClass: sdcsSubscriber
objectClass: top
postalCode: 29600
sdcsServiceLevel: 10
sdcsCustomerType: 14
givenName: Adelia
sdcsBlackListAll: FALSE
sdcsOwnerType: T-Mobile
sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies
6. Shell Programming and Scripting
Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given
Name Domain Contact Phone Email Location
----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies
7. Shell Programming and Scripting
hi i need the shell script to get the file with latest date.
for example in my input folder i have files like
file_20130212.txt
file_20130211.txt
now my output folder should have the file with latest date i.e..file_20120212.txt
i want to get the latest file .. i.e is should take... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies
8. Shell Programming and Scripting
Hi,
I am trying to find the weblogic home directory whether it is installed in the Linux box. if it is existing display the weblogic home and the corresponding Java home directory else display message as that wl home does not exist. I already wrote a program but it was not working properly.... (11 Replies)
Discussion started by: spgreddy
11 Replies
9. Shell Programming and Scripting
Hi I am using below code to check the WEBLOGIC substate ealth but getting sytax error.. can anyone help?
servers=domainRuntimeService.getServerRuntimes()
for server in servers:
components=server.getSubsystemHealthStates()
componentsList = components.tolist()
for component in... (2 Replies)
Discussion started by: varun22486
2 Replies
10. Shell Programming and Scripting
I am attempting to write a korn shell script that does the following, but I am getting errors. I'm new to korn shell scripting and am not sure what I am doing wrong. Please help with example scripts. Thanks.
1) check for day of the week
2) if day of the week is Monday then check for the... (4 Replies)
Discussion started by: ijmoore
4 Replies