cancel
Showing results for 
Search instead for 
Did you mean: 

Script help

 
SOLVED
Go to solution
Highlighted
Honored Contributor

Script help

I have a script that I did not write and the developers would like it modified to tell them which tomcat node their application is deployed on. Something like appdeploy <ENVIRONMENT> <APPNAME> and it would tell them which tomcat node their application is on. Any help would be greatly appreciated.

 

 

#!/bin/bash

# 23Mar2010 - Not written by me :{

# Used to deploy applications to tomcat6 nodes.

 

# Function Declarations

########################################################################################

function get_node {

case $ENVIRONMENT in

beta|prod)

case $1 in

app1) NODE="${ENVIRONMENT}-tc5";;

app2) NODE="${ENVIRONMENT}-tc5";;

app3) NODE="${ENVIRONMENT}-tc1";;

app4) NODE="${ENVIRONMENT}-tc2";;

app5) NODE="${ENVIRONMENT}-tc7";;

app6) NODE="${ENVIRONMENT}-tc11";;

app7) NODE="${ENVIRONMENT}-tc3";;

app8) NODE="${ENVIRONMENT}-tc7";;

app9) NODE="${ENVIRONMENT}-tc8";;

app10) NODE="${ENVIRONMENT}-tc9";;

app11) NODE="${ENVIRONMENT}-tc2";;

app12) NODE="${ENVIRONMENT}-tc3";;

app13) NODE="${ENVIRONMENT}-tc10";;

app14) NODE="${ENVIRONMENT}-tc6";;

app15) NODE="${ENVIRONMENT}-tc8";;

app16) NODE="${ENVIRONMENT}-tc9";;

app17) NODE="${ENVIRONMENT}-tc10";;

app18) NODE="${ENVIRONMENT}-tc4";;

app19) NODE="${ENVIRONMENT}-tc4";;

app20) NODE="${ENVIRONMENT}-tc10";;

app21) NODE="${ENVIRONMENT}-tc3";;

app22) NODE="${ENVIRONMENT}-tc5";;

app23) NODE="${ENVIRONMENT}-tc4";;

app22) NODE="${ENVIRONMENT}-tc5";;

app23) NODE="${ENVIRONMENT}-tc5";;

app24) NODE="${ENVIRONMENT}-tc7";;

app25) NODE="${ENVIRONMENT}-tc8";;

app26) NODE="${ENVIRONMENT}-tc4";;

*)

echo "The application ${APPNAME} is not configured. Please contact the systems team."

exit;;

esac;;

*)

echo "${ENVIRONMENT} is not a valid environment."

exit 1;;

esac

}

 

function usage {

echo -e "Usage: appdeploy <ENVIRONMENT> <WARFILE> <APPNAME>\n"

echo "Example:"

echo "appdeploy beta /mnt/dist/tomcat/application/beta/application-3.0.4.war application"

exit

}

 

function check_filename {

FILE=`echo $1 | tr [:upper:] [:lower:]`

EXT=${FILE##*.}

if [ ${EXT} != "war" ]; then

usage

fi

}

 

function confirm {

read -p "Confirm deploy of ${WARFILE} to ${NODE} as ${APPNAME}? [y/N]" yn

RESPONSE=`echo $yn | tr [:upper:] [:lower:]`

case $RESPONSE in

y|yes)

DEPLOY="yes";;

*)

DEPLOY="no";;

esac

}

########################################################################################

 

# Check for arguments passed and display usage if they don't make sense.

if [ $# -ne 3 ]; then

usage

exit 1

fi

 

# Set variables from command-line arguments

ENVIRONMENT=`echo $1 | tr [:upper:] [:lower:]`

WARFILE=$2

APPNAME=$3

 

# Check that the first variable is a war file

check_filename $WARFILE

 

# Determine which node to deploy to

get_node $APPNAME

 

# Confirm deploy

confirm

if [ ${DEPLOY} = "yes" ]; then

#create "current" symlink on /mnt/dist

WAR=`basename $WARFILE`

PTH=`dirname $WARFILE`

echo "Changing current pointer..."

ln -s -f ${WARFILE} ${PTH}/current

echo "Deploying application..."

scp ${WARFILE} ${NODE}:/usr/local/tomcat/webapps/${APPNAME}.war

echo "Application Deployed."

exit

else

echo "Deploy Aborted."

fi

 

2 REPLIES 2
Highlighted
Acclaimed Contributor
Solution

Re: Script help

>would like it modified to tell them which tomcat node their application is deployed on.

 

It appears that your function get_node has the info you need.

You could change the UI from: appdeploy <ENVIRONMENT> <WARFILE> <APPNAME>

To also include: appdeploy <ENVIRONMENT> <APPNAME>

 

(I would add a "-" option instead of basing it on the number of parms.)

 

By checking the number of parms:

if [ $# -eq 2 ]; then

   # Set variables from command-line arguments

   ENVIRONMENT=`echo $1 | tr [:upper:] [:lower:]`

   APPNAME=$2

   # Determine which node to deploy to

   get_node $APPNAME

   echo "Deployed on $NODE"

   exit 0

fi

 

And then the existing:

 

# Check for arguments passed and display usage if they don't make sense.

if [ $# -ne 3 ]; then

 

And of course update the usage:

function usage {

echo -e "Usage: appdeploy <ENVIRONMENT> <WARFILE> <APPNAME>"

echo -e "Usage: appdeploy <ENVIRONMENT> <APPNAME>\n"

 

echo "If <WARFILE> is missing, the NODE is displayed."

Highlighted
Honored Contributor

Re: Script help

Thanks alot Dennis that did the trick