Help needed with a shell script for deploying ear file to a weblogic server using WLST


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed with a shell script for deploying ear file to a weblogic server using WLST
# 1  
Old 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!
# 2  
Old 07-30-2014
Hi Amulya,

Nice script to deploy applications. Can the script be modified to get the values/parameters from a file rather than providing in the command line.

It is too long to run giving all the values.
e.g: java weblogic.WLST autodeploy.py -u username -p password -a adminUrl [<hostname>:<port>] -n deploymentName -f deploymentFile -t deploymentTarget

Instead can the script get the values from a separate file or within the script.

Please let me know how it can be done.

Many thanks....
# 3  
Old 08-01-2014
I tried to run the script but it is not working.

I have not modified your script and tried to run with the following command line:

java weblogic.WLST autodeploy.py -u weblogic -p password123 -a [localhost:7001] -n ShoppingCart -f ShoppingCart.war -t AdminServer

The WLST is started but the script is not executed. All I see is


Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

and it exists.

Could you please advise if I have missed something

Thanks...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Needed with File Checker Korn Shell Script

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

2. Shell Programming and Scripting

WLST script python

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

3. Shell Programming and Scripting

Shell script to find weblogic home directory

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

4. Shell Programming and Scripting

Needed shell script to get the latest file based on date

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

5. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

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

6. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

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

7. Shell Programming and Scripting

Get the STATE of the weblogic instances via shell script.

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

8. Solaris

deploying .ear file Websphere

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

9. Shell Programming and Scripting

Script needed to FTP a file from sql report to unix server

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

10. Shell Programming and Scripting

Weblogic monitoring shell script

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
Login or Register to Ask a Question