mardi 29 décembre 2015

for loop inside a case statement

I am trying to execute a stop/start script on client machine from remote jump server. I want to run a for loop where it takes Jboss instance names and stop/start the instances one by one on client machine. The script is not able to get the instance names from the variable instance which is defined before the case statement.

#!/bin/bash
sudo su - username <<EOF
instance="instance1 instance2"
case $1 in
stop)
        case $2 in
        all)
                #STOP ALL JBOSS INSTANCES
                for i in $instance
                do
                echo "checking if $i instance on the server are running or not"
                f_isjboss $i | head -2
                if [[ $(ps -aef --width 2000 | grep 'run.sh' | grep "\-c $i " | grep java | grep -v grep | wc -l) -gt 0 ]]
                then
                echo "$i instance is running and script will kill the process"
                f_stopjboss $i
                echo "tailing the server.log file to make sure shutdown is complete"
                grep -m 1 "Shutdown complete" <(tail -f /opt/sw/jboss/jboss/jboss-eap-5.2/jboss-as/server/$i/log/server.log | tee /dev/tty);
                sleep 2s
                echo "$i Shutdown Command executed successfully and script will continue to next instance"
                else
                echo "$i instance is not running and script will continue to next instance"
                fi
                done
                ;;
        esac
        ;;

Aucun commentaire:

Enregistrer un commentaire