Date Created: Sun 10-Feb-2008

Related Document Categories:



    How to use a shell script to End a WebSphere MQ Queue Manager and poll status until complete.

    endqm.sh

    #!/bin/bash
    # BASH Functions file
    # Filename: endqm.sh
    # Tested on OS: Linux, Fedora 6
    # Author: Steve Robinson
    # Date Created: February 2008
    # Arguments: Queue Manager Name
    # Decription: This script ends a queue manager and pools the Queue Manager status until ended
    # Version: 1.0
    # History:-
    # 10-February-2008 - version 1.0 - Created.
    ###################################################################################
    ## Global Variables
    ###################################################################################
    localHost=$(hostname)
    _DEBUG="on"
    ###################################################################################
    ## Debug Function
    ###################################################################################
    DEBUG()
    {
    [ "$_DEBUG" == "on" ] && $@ || :
    }

    #####################################################################################
    ## Main Routine
    #####################################################################################

    main() {

    DEBUG echo "Status: Entering Main Routine.. "
    DEBUG echo "Status: Checking to see if [$qmname] exists? ..."

    qm=`dspmq | awk '{ print $1 }' | sed 's/QMNAME(//g;s/)//g' | grep -o $qmname`
    if [ "$qm" = "" ];
    then
    DEBUG echo "Status: [$qmname] does not exist!"
    `crtmqm $qmname`
    DEBUG echo "Failure: Exiting with value 1"
    else
    DEBUG echo "Status: [$qmname] exists"
    status=`dspmq -m $qmname| cut -d '(' -f2,3 | cut -d ')' -f2 | cut -d '(' -f2`
    DEBUG echo status of queue manager [$qmname] is [$status]
    if [ "$status" = "Running" ]
    then
    DEBUG echo "Status: Ending: [$qmname]"
    endmqm $qmname

    while [ "$status" != "Ended normally" ]
    do
    sleep 5
    echo "Ending..."
    status=`dspmq -m $qmname| cut -d '(' -f2,3 | cut -d ')' -f2 | cut -d '(' -f2`
    done
    DEBUG echo status of queue manager [$qmname] is [$status]
    DEBUG echo "Success: Exiting with value 0"
    fi
    fi
    }




    ####################################################################################
    ## Entry Point
    ####################################################################################
    DEBUG echo There are $# arguments to $0: $*
    #Checking environment variables
    if [ ! "$1" ];
    then
    DEBUG echo "Failure: You must pass in a queue manager name"
    DEBUG echo "exiting with value 1"
    exit 1
    else

    qmname=$1
    DEBUG echo "Status: Queue Manager to end = $qmname"
    DEBUG echo "Status: Calling Main Routine ... "

    main $*

    DEBUG echo "Exit: Exiting Main Routine and Terminating script ... "
    exit 0

    fi

Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories