1834020 Members
2824 Online
110063 Solutions
New Discussion

Script help needed

 
SOLVED
Go to solution
Hunki
Super Advisor

Script help needed

Attached is part of a case statement of a script that I have to use to boot up JBOSS on a system. The thing is I have three instances of JBOSS ( REST-A/B/C ) for starting all three instances in the case statement I have function called check_"instance-name" to see if the instance is already up .

But the problem is if the instance is already up then how to make it switch to the next checking of the instance and then the next one within the case statement so that it does not start duplicate instances.

thanks in anticipation,
hunki
11 REPLIES 11
James R. Ferguson
Acclaimed Contributor

Re: Script help needed

Hi:

One way would be to have a 'while' loop that runs until a maximum count of running objects is tallied by the 'case'.

Regards!

...JRF...
Hunki
Super Advisor

Re: Script help needed

I dont get it ... can u show me within the script on how to do it please.

thanks,
Raj D.
Honored Contributor

Re: Script help needed

Hunki,

Here is an example with the case statement.

#----------------------------------------
#!/bin/sh
# An example with the case statement
# Reads a command from the user and processes it
echo "Enter your command (who, list, or cal)"
read command
case "$command" in
who)
echo "Running who..."
who
;;
list)
echo "Running ls..."
ls
;;
cal)
echo "Running cal..."
cal
;;
*)
echo "Bad command, your choices are: who, list, or cal"
;;
esac
exit 0
#----------------------------------



Hope this will help,

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Hunki
Super Advisor

Re: Script help needed

read my question raj ...
Sandman!
Honored Contributor
Solution

Re: Script help needed

How about extending your decision statement for example:

check_REST-A && echo "JBoss - REST-A already running!" ||
(
echo "Starting JBOSS-A";
su - gt -c "nohup /export/home/tmp/mc/jboss-4.0.4.GA/bin/run.sh -c REST-A";
echo "Server startup may take a while - "
)

~hope it helps
James R. Ferguson
Acclaimed Contributor

Re: Script help needed

Hi (again):

Consider something like this:

# cat ./looper
#!/usr/bin/sh
typeset -l REPLY
typeset FLAG_A=0
typeset FLAG_B=0
typeset FLAG_C=0
while true
do
echo "please respond..."
read REPLY
case ${REPLY} in
"a" )
[ ${FLAG_A} = 1 ] && echo "already done" || FLAG_A=1
;;
"b" )
[ ${FLAG_B} = 1 ] && echo "already done" || FLAG_B=1
;;
"c" )
[ ${FLAG_C} = 1 ] && echo "already done" || FLAG_C=1
;;
esac

[ ${FLAG_A} = 1 -a ${FLAG_B} = 1 -a ${FLAG_C} = 1 ] && break
done
echo "done!"
exit 0

...When executed, this script will run forever until it receives an "a", "b" or "c" set of responses. Duplicate responses are ignored. Input can be upper or lower case.

In the absence of a blocking I/O like a 'read' in this script, add a 'sleep' to the loop so that you do not needlessly consume the CPU.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: Script help needed

Sorry for not misunderstanding the question!

To check the next checking of the instance after the first check , hope you can use decission making and flow control with " if then else" loop , what do you think.

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: Script help needed

Pls eliminate "not" in my last post.

P.S: "0" point pls. Thx.
" If u think u can , If u think u cannot , - You are always Right . "
SANTOSH S. MHASKAR
Trusted Contributor

Re: Script help needed

Hi,

Use for loop

eg.


for Instance in REST-A REST-b REST-C
do
check_${Instance} && echo "Already UP ${Instance}"
..
..
..
done


-Santosh
Hunki
Super Advisor

Re: Script help needed

Thanks Sandman and thanks also to James, Raj , Santosh for replying.
Raj D.
Honored Contributor

Re: Script help needed

Btw, Hunki did you got any solution, and would you like to share as how this is resolved.

Thanks,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "