Help modifying a unix shell script?

Hello,

I have a script that was created by a previous sysadmin that I need to change to add more functionality to, attached is the actual script (appstart.sh):

#!/bin/ksh

# Changes:
# 02-27-11 - mirde - Created.

# cd to WRKDIR so proset.env can be found
cd /usr1/logs/appsrv

echo "Starting adminserver at `date` ..."
${DLC}/bin/proadsv -start

echo "Waiting for good startup status from the AdminServer..."
STAT=bad
tries=0
while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit

  echo ">>Checking the AdminServer"
  ${DLC}/bin/proadsv -query
  case "`${DLC}/bin/proadsv -query`" in
    *not?alive*) STAT=bad;;
    *alive*) STAT=good;;
    *) STAT=bad;;
  esac
done

echo "Starting (Appserver) cfgmgr at `date` ..."
${DLC}/bin/asbman -name cfgmgr -start

echo "Starting (Appserver) production at `date` ..."
${DLC}/bin/asbman -name cfgmgrp -start
${DLC}/bin/asbman -name production -start
${DLC}/bin/asbman -name productiona -start
echo "\n\n"

echo "Starting (Appserver) development at `date` ..."
${DLC}/bin/asbman -name cfgmgrd -start
${DLC}/bin/asbman -name development -start
${DLC}/bin/asbman -name developmenta -start
echo "\n\n"

echo "Starting (Appserver) training at `date` ..."
${DLC}/bin/asbman -name cfgmgrt -start
${DLC}/bin/asbman -name training -start
${DLC}/bin/asbman -name traininga -start
echo "\n\n"

echo "Starting (Appserver) testing at `date` ..."
${DLC}/bin/asbman -name cfgmgrs -start
${DLC}/bin/asbman -name testing -start
${DLC}/bin/asbman -name testinga -start
echo "\n\n"

echo "AppServer startup completed at `date`"

Open in new window


I am trying to add paramters to the script, so that I can call the script such as:

appstart.sh [param]

The param being = prod, test, train or devel.

If I punch in appstart.sh devel I want it to only run:

echo "Starting (Appserver) development at `date` ..."
${DLC}/bin/asbman -name cfgmgrd -start
${DLC}/bin/asbman -name development -start
${DLC}/bin/asbman -name developmenta -start
echo "\n\n"

Open in new window


Anyone experienced in shell scripting able to help me out?

If nothing is entered, only the script called appstart.sh, i want it to output what the user can call the script with.. something like "call script passing in environment name: appstart devel".

Thanks for your help.
mirdeAsked:
Who is Participating?
 
sweetfa2Commented:
#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

startProduction() {
        startServer PRODUCTION 20931 7842
}

startDevelopment() {
        startServer DEVELOPMENT 20932 7843
}

startTest() {
        startServer TESTING 20934 7845
}

startTraining() {
        startServer TRAINING 20933 7844
}

startServer() {
        environ=$1
        port=$2
        adminport=$3

        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $adminport -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 5 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
echo "Starting (Appserver) cfgmgr at `date` ..."
${DLC}/bin/asbman -name cfgmgr -port $port -start

${DLC}/bin/asbman -name cfgmgrp -port $port -start
${DLC}/bin/asbman -name ${environ} port $port -start
${DLC}/bin/asbman -name ${environ}a -port $port -start
echo "\n\n"
        done


}


if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startProduction
;;
 development|devel)
        startDevelopment
;;
 testing|test)
        startTesting
;;
  training|train)
        startTraining
;;
  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window

0
 
sweetfa2Commented:
#!/bin/ksh

# Changes:
# 02-27-11 - mirde - Created.

if [ $# -ne 1 ];
then
    usage
fi

environ=$1
case $environ in
  production) ;;
  test);;
  train)
        environ=training
        ;;
  devel)
       environ=development
      ;;
  *)
       usage
       ;;
esac

# cd to WRKDIR so proset.env can be found
cd /usr1/logs/appsrv

echo "Starting adminserver at `date` ..."
${DLC}/bin/proadsv -start

echo "Waiting for good startup status from the AdminServer..."
STAT=bad
tries=0
while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit

  echo ">>Checking the AdminServer"
  ${DLC}/bin/proadsv -query
  case "`${DLC}/bin/proadsv -query`" in
    *not?alive*) STAT=bad;;
    *alive*) STAT=good;;
    *) STAT=bad;;
  esac
done

echo "Starting (Appserver) cfgmgr at `date` ..."
${DLC}/bin/asbman -name cfgmgr -start

echo "Starting (Appserver) ${environ} at `date` ..."
${DLC}/bin/asbman -name cfgmgrp -start
${DLC}/bin/asbman -name ${environ} -start
${DLC}/bin/asbman -name ${environ}a -start
echo "\n\n"

echo "AppServer startup completed at `date`"

Open in new window

0
 
mirdeAuthor Commented:
Thanks for your reply, using your example here is what I was able to put together..

#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
 cd $WRKDIR
 echo "Starting the PRODUCTION AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20931 -adminport 7842 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the PRODUCTION AdminServer on `date`"
 ${DLC}/bin/proadsv -port 20931 -query
  case "`${DLC}/bin/proadsv -port 20931 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
;;
 development|devel)
 cd $WRKDIR
 echo "Starting the DEVELOPMENT AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20932 -adminport 7843 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the DEVELOPMENT AdminServer"
 ${DLC}/bin/proadsv -port 20932 -query
  case "`${DLC}/bin/proadsv -port 20932 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
;;
 training|train)
 cd $WRKDIR
 echo "Starting the TRAINING AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20933 -adminport 7844 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the TRAINING AdminServer"
 ${DLC}/bin/proadsv -port 20933 -query
  case "`${DLC}/bin/proadsv -port 20933 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
;;
 testing|test)
 cd $WRKDIR
 echo "Starting the TESTING AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20934 -adminport 7845 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the TESTING AdminServer"
 ${DLC}/bin/proadsv -port 20934 -query
  case "`${DLC}/bin/proadsv -port 20934 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window


How can I make it so that, if I call the program with "appstart all", it starts all 4 $opt (Prod, devel, test and train).

Is that possible?

Thanks.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sweetfa2Commented:
#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

startProduction() {
        startServer PRODUCTION 20931 7842
}

startDevelopment() {
        startServer DEVELOPMENT 20932 7843
}

startTest() {
        startServer TESTING 20934 7845
}

startTraining() {
        startServer TRAINING 20933 7844
}

startServer() {
        environ=$1
        port=$2
        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport 7842 -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 5 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
        done
}


if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startProduction
;;
 development|devel)
        startDevelopment
;;
 testing|test)
        startTesting
;;
  training|train)
        startTraining
;;
  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window

0
 
sweetfa2Commented:
Change line 29 to

${DLC}/bin/proadsv -port $port -adminport $3 -start
0
 
mirdeAuthor Commented:
Hi Sweetfa2,

Your script looks great, just what I was looking for.. there was code in my example I did not include.. as per below..

#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
 #Start the Production AdminServer & Verify
 cd $WRKDIR
 echo "Starting the PRODUCTION AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20931 -adminport 7842 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit

 echo "Checking the PRODUCTION AdminServer on `date`"
 ${DLC}/bin/proadsv -port 20931 -query
  case "`${DLC}/bin/proadsv -port 20931 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
 #Start the Production Application Servers
 echo "Starting (Appserver) cfgmgr at `date` ..."
 ${DLC}/bin/asbman -name cfgmgr -port 20931 -start
 echo "Starting (Appserver) production at `date` ..."
 ${DLC}/bin/asbman -name cfgmgrp -port 20931 -start
 ${DLC}/bin/asbman -name production -port 20931 -start
 ${DLC}/bin/asbman -name productiona -port 20931 -start
 echo "\n\n"
 development|devel)
 ;;
 cd $WRKDIR
 #Start the Development AdminServer & Verify
 echo "Starting the DEVELOPMENT AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20932 -adminport 7843 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the DEVELOPMENT AdminServer"
 ${DLC}/bin/proadsv -port 20932 -query
  case "`${DLC}/bin/proadsv -port 20932 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
 #Start the Development Application Servers
 echo "Starting (Appserver) DEVELOPMENT at `date` ..."
 ${DLC}/bin/asbman -name cfgmgrd -port 20932 -start
 ${DLC}/bin/asbman -name development -port 20932 -start
 ${DLC}/bin/asbman -name developmenta -port 20932 -start
 echo "\n\n"
;;
 training|train)
 cd $WRKDIR
 #Start the Training AdminServer & Verify
 echo "Starting the TRAINING AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20933 -adminport 7844 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the TRAINING AdminServer"
 ${DLC}/bin/proadsv -port 20933 -query
  case "`${DLC}/bin/proadsv -port 20933 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
 #Start the Training Application Servers
 echo "Starting (Appserver) Training at `date` ..."
 ${DLC}/bin/asbman -name cfgmgrt -port 20933 -start
 ${DLC}/bin/asbman -name training -port 20933 -start
 ${DLC}/bin/asbman -name traininga -port 20933 -start
 echo "\n\n"
;;
 testing|test)
 cd $WRKDIR
 #Start the Testing AdminServer & Verify
 echo "Starting the TESTING AdminServer on `date`."
 ${DLC}/bin/proadsv -port 20934 -adminport 7845 -start

 echo "Waiting for good start from AdminServer."
 STAT=bad
 tries=0
  while [ "${STAT}" != "good" ]; do
  let "tries=tries+1"
  [ $tries -gt 5 ] && exit
 
 echo "Checking the TESTING AdminServer"
 ${DLC}/bin/proadsv -port 20934 -query
  case "`${DLC}/bin/proadsv -port 20934 -query`" in
   *not?alive*) STAT=bad;;
   *alive*) STAT=good;;
   *) STAT=bad;;
 esac
 done
 #Start the Testing Application Servers
 echo "Starting (Appserver) TESTING at `date` ..."
 ${DLC}/bin/asbman -name cfgmgrs -port 20934 -start
 ${DLC}/bin/asbman -name testing -port 20934 -start
 ${DLC}/bin/asbman -name testinga -port 20934 -start
 echo "\n\n"
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window


If you look, for each environment, I also need to add:

 ${DLC}/bin/asbman -name cfgmgr -port 20931 -start
 ${DLC}/bin/asbman -name cfgmgrp -port 20931 -start
 ${DLC}/bin/asbman -name production -port 20931 -start
 ${DLC}/bin/asbman -name productiona -port 20931 -start

After the AdminServer start up, could this be incorporated into it? I attached above how I did it , but your code looks much more sophisticated to work with.
0
 
mirdeAuthor Commented:
I think, I need to incorporate it in a way so that I can pass in:

startProduction() {
        startServer PRODUCTION 20931 7842 cfgmgr cfgmgrp production productiona
}

Then, under..

startServer() {

${DLC}/bin/asbman -name $something -port $something -start

}

?? however I am not a 100% sure how to do this.. this would complete the script I need.
0
 
sweetfa2Commented:
You may need to move line 54 before line 47 depending on what this stuff actually does
0
 
mirdeAuthor Commented:
Hi Sweetfa2,

Thanks, this is getting there... essentially the AdminServer needs to start first by calling it first.. then the "cfgmgr" server followed by specific environment or "all".

In your code example..

startServer() {
        environ=$1
        port=$2
        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $3 -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 5 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
echo "Starting ${environ} cfgmgr at `date` ..."
${DLC}/bin/asbman -name cfgmgr -port $port -start
${DLC}/bin/asbman -name cfgmgrp -port $port -start
${DLC}/bin/asbman -name ${environ} port $port -start
${DLC}/bin/asbman -name ${environ}a -port $port -start
echo "\n\n"
        done
}

Open in new window


For "production" I need it to run:

 ${DLC}/bin/asbman -name cfgmgrp -port 20931 -start
 ${DLC}/bin/asbman -name production -port 20931 -start
 ${DLC}/bin/asbman -name productiona -port 20931 -start

Open in new window


for devel, it needs:
 ${DLC}/bin/asbman -name cfgmgrd -port 20932 -start
 ${DLC}/bin/asbman -name development -port 20932 -start
 ${DLC}/bin/asbman -name developmenta -port 20932 -start

Open in new window


Your code works, except for prod one of the servers name is "cfgmgrp" where in development, it is "cfgmgrd", and training "cfgmgrt".

So, could I do something like..

startProduction() {
        startServer PRODUCTION 20931 7842 cfgmgrp
}

echo "Starting (Appserver) cfgmgr at `date` ..."
${DLC}/bin/asbman -name $-port $port -start
${DLC}/bin/asbman -name $4 -port $port -start
${DLC}/bin/asbman -name ${environ} port $port -start
${DLC}/bin/asbman -name ${environ}a -port $port -start
echo "\n\n"
        done

Open in new window


Would $4 be the next call to that value?
0
 
mirdeAuthor Commented:
Would it be possible to code it like this..

startTraining() {
		startServer TRAINING 20933 7844
        startApp production productiona cfgmgrp
}
startServer() {
        environ=$1
        port=$2
        adminport=$3

        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $adminport -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 5 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
}
startApp() {
        config=$1
        reg=$2
        async=$3

cd $WRKDIR
echo "Starting AppServers at `date` ..."
${DLC}/bin/asbman -name $1 -port $port -start
}

if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startTraining
		startApp
;;

Open in new window


So calling training, it would do "startServer" and "startApp" ? If that works, then how would we handle this part:

${DLC}/bin/asbman -name $1 -port $port -start

As there are values for $1, $2 and $3.

Thanks for your ongoing help, this will help me very much as I won't have to always manually enter these commands :)
0
 
sweetfa2Commented:
You can code it anyway you want.

$1, $2 etc are the parameters you pass to the function

ie. startApp production productiona cfgmrgd

means that prodution=$1, productiona=$2 and cfgmrgd=$3

${1}a will give you productiona as well so you don't necessarily need to pass productiona unless you are likely to have a productionb

If you need to deal with the port you will need to pass another parameter as per the other scripts I have done.
0
 
mirdeAuthor Commented:
Thanks, here is how my final code would look like..

#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

startProduction() {
        startServer PRODUCTION 20931 7842
		startApp cfgmgrp production productiona
}

startDevelopment() {
        startServer DEVELOPMENT 20932 7843
		startApp cfgmgrd development developmenta
}

startTest() {
        startServer TESTING 20934 7845
		startApp cfgmgrs testing testinga
}

startTraining() {
        startServer TRAINING 20933 7844
		startApp cfgmgrt training traininga
}

startServer() {
        environ=$1
        port=$2
        adminport=$3

        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $adminport -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 5 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
}

startApp() {
        cfg=$1
        reg=$2
        syn=$3

		cd $WRKDIR
		echo "Starting AppServers at `date` ..."
		${DLC}/bin/asbman -name $1 -port $port -start
		${DLC}/bin/asbman -name $2 -port $port -start
		${DLC}/bin/asbman -name $3 -port $port -start
}


if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startProduction
;;
 development|devel)
        startDevelopment
;;
 testing|test)
        startTesting
;;
  training|train)
        startTraining
;;
  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window


Is there a way to avoid having to do...

            ${DLC}/bin/asbman -name $1 -port $port -start
            ${DLC}/bin/asbman -name $2 -port $port -start
            ${DLC}/bin/asbman -name $3 -port $port -start

To call all $1-$3 values ?
0
 
mirdeAuthor Commented:
Ok.. after digging into this some more.. here is what I have (completed) i think..

#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

startProduction() {
        startServer PRODUCTION 20931 7842
		startApp 20931 cfgmgrp production productiona
}

startDevelopment() {
        startServer DEVELOPMENT 20932 7843
		startApp 20932 fgmgrd development developmenta
}

startTest() {
        startServer TESTING 20934 7845
		startApp 20934 cfgmgrs testing testinga
}

startTraining() {
        startServer TRAINING 20933 7844
		startApp 20933 cfgmgrt training traininga
}

startCfg() {
        startCfg 20931 cfgmgr
}

startServer() {
        environ=$1
        port=$2
        adminport=$3

        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $adminport -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 3 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
}

startApp() {
		port=$1
        cfgmgr=$2
        regular=$3
        async=$4

		cd $WRKDIR
		echo "Starting AppServers at `date` ..."
		${DLC}/bin/asbman -name $cfgmgr -port $port -start
		${DLC}/bin/asbman -name $regular -port $port -start
		${DLC}/bin/asbman -name $async -port $port -start
}

startCfg() {
		port=$1
		cfgmgr=$2
		${DLC}/bin/asbman -name $cfgmgr -port $port -start
}


if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startProduction
;;
 development|devel)
        startDevelopment
;;
 testing|test)
        startTesting
;;
  training|train)
        startTraining
;;
  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
		startCfg
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window


When I call the "all" option, how is this going to execute? startDevelopment first and startCfg last?
0
 
sweetfa2Commented:
Yes, the order is dependant on the order you have in the list.

Your startCfg will fail because you are not passing any parameters to it.

If this needs to start for every environment or when you start only one environment then it probably needs to be moved or added elsewhere.
0
 
mirdeAuthor Commented:
If I call..

  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
        startCfg
;;

The "startCfg" setting is defined here..

startCfg() {
       StartCfg 20931 cfgmgr
}

startCfg() {
        port=$1
        cfgmgr=$2
        ${DLC}/bin/asbman -name $cfgmgr -port $port -start
}

The way I understand it, wouldn't "StartCfg 20931 cfgmgr" be passing in the parameters ?
0
 
mirdeAuthor Commented:
the "startCfg" should be stated only if we are calling "everything" and not the specific environments.
0
 
sweetfa2Commented:
yes - startCfg 20931 cfgmgr is passing in the parameters you require.

However, you seem to have a duplicate which will confuse the issue

all)
startDevelopment
startTesting
...
startCfg 20931 cfgmgr
;;


is what you really want.  Not
startCfg() {
StartCfg 20931...

0
 
mirdeAuthor Commented:
My apology, I am not sure I understand your example.. would the following fix it?

#!/bin/ksh

# Changes:
# 12-09-11 - mirde - Updated script to support multiple AdminServers.

WRKDIR=/usr1/logs/appsrv

startProduction() {
        startServer PRODUCTION 20931 7842
        startApp 20931 cfgmgrp production productiona
}

startDevelopment() {
        startServer DEVELOPMENT 20932 7843
        startApp 20932 fgmgrd development developmenta
}

startTest() {
        startServer TESTING 20934 7845
        startApp 20934 cfgmgrs testing testinga
}

startTraining() {
        startServer TRAINING 20933 7844
        startApp 20933 cfgmgrt training traininga
}

startCfg() {
        startCfgMan 20931 cfgmgr
}

startServer() {
        environ=$1
        port=$2
        adminport=$3

        cd $WRKDIR
        echo "Starting the $environ AdminServer on `date`."
        ${DLC}/bin/proadsv -port $port -adminport $adminport -start

        echo "Waiting for good start from AdminServer."
        STAT=bad
        tries=0
        while [ "${STAT}" != "good" ]; do
          let "tries=tries+1"
          [ $tries -gt 3 ] && exit
         
                echo "Checking the $environ AdminServer on `date`"
                ${DLC}/bin/proadsv -port $port -query
                case "`${DLC}/bin/proadsv -port $port -query`" in
                 *not?alive*) STAT=bad;;
                 *alive*) STAT=good;;
                 *) STAT=bad;;
                esac
}

startApp() {
        port=$1
        cfgmgr=$2
        regular=$3
        async=$4

        cd $WRKDIR
        echo "Starting AppServers at `date` ..."
        ${DLC}/bin/asbman -name $cfgmgr -port $port -start
        ${DLC}/bin/asbman -name $regular -port $port -start
        ${DLC}/bin/asbman -name $async -port $port -start
}

startCfgMan() {
        port=$1
        cfgmgr=$2
        ${DLC}/bin/asbman -name $cfgmgr -port $port -start
}


if [[ ! -n $1 ]] ; then
 echo " You did not specify an environment."
 echo " Call the script with: appstart [environment]"
 exit 99
fi

opt=$1
case "$opt" in
 production|prod|live)
        startProduction
;;
 development|devel)
        startDevelopment
;;
 testing|test)
        startTesting
;;
  training|train)
        startTraining
;;
  all)
        startDevelopment
        startTesting
        startTraining
        startProduction
        startCfg
;;
 *) clear
 echo "Your syntax is incorrect!" ; exit 99;;
esac

echo "AppServer startup completed at `date`"

Open in new window

0
 
sweetfa2Commented:
Yes
0
 
mirdeAuthor Commented:
Thanks for your help, appreciate your expertise on this !!
0
 
mirdeAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for mirde's comment http:/Q_27485321.html#37264893

for the following reason:

Script does exactly as I envisioned it, beats what I originally started with by a mile.
0
 
mirdeAuthor Commented:
Clicked the wrong button, do not close the KB but award the user sweetfa2 !!
0
 
mirdeAuthor Commented:
Works exactly was I wanted it to.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.