LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Probem with case statement in shel programing (https://www.linuxquestions.org/questions/linux-newbie-8/probem-with-case-statement-in-shel-programing-795449/)

srinivas_uga 03-15-2010 01:43 AM

Probem with case statement in shel programing
 
Hi Friends,

I am facing problem with the following script. Could you please look into this.

echo 'Enter Staging number'
case $STGNUM in
1)
for i in {'stg1-greg','stg1-marsha','stg1-peter','stg1-jan','stg2-greg','stg2-marsha','stg2-peter','stg2-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;
for i in {'stg1-greg','stg2-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/stopwfjms.sh;done;
for i in {'stg1-greg','stg2-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/runwfjms.sh;done;
for i in {'stg1-greg','stg1-marsha','stg1-peter','stg1-jan','stg2-greg','stg2-marsha','stg2-peter','stg2-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/runwf.sh;done;

3)
for i in {'stg3-greg','stg3-marsha','stg3-peter','stg3-jan','stg4-greg','stg4-marsha','stg4-peter','stg4-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;

for i in {'stg3-greg','stg4-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/stopwfjms.sh;done;

for i in {'stg3-greg','stg4-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/runwfjms.sh;done;

for i in {'stg3-greg','stg3-marsha','stg3-peter','stg3-jan','stg4-greg','stg4-marsha','stg4-peter','stg4-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/runwf.sh;done;



7)
for i in {'stg7-greg','stg7-marsha','stg7-peter','stg7-jan','stg8-greg','stg8-marsha','stg8-peter','stg8-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;

for i in {'stg7-greg','stg8-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/stopwfjms.sh;done;

for i in {'stg7-greg','stg8-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/runwfjms.sh;done;

for i in {'stg7-greg','stg7-marsha','stg7-peter','stg7-jan','stg8-greg','stg8-marsha','stg8-peter','stg8-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/runwf.sh;done;


9)
for i in {'stg9-greg','stg9-marsha','stg9-peter','stg9-jan','stg10-greg','stg10-marsha','stg10-peter','stg10-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;

for i in {'stg9-greg','stg10-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/stopwfjms.sh;done;

for i in {'stg9-greg','stg10-greg'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/wfjmssf/runwfjms.sh;done;

for i in {'stg9-greg','stg9-marsha','stg9-peter','stg9-jan','stg10-greg','stg10-marsha','stg10-peter','stg10-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/runwf.sh;done;

*)
echo "entered wrong staging no"
esac


Error:

[suga@stg7-greg workflow]$ dev ./Test1.sh
Enter Staging number
./Test1.sh: line 9: syntax error near unexpected token `)'
./Test1.sh: line 9: `3)'


Thanks,
U.Srinivas

mario.almeida 03-15-2010 01:52 AM

Hi,
Your are missing --> ;; after each case

case $1 in

1)
do something ;
do something ;; <--
2)
do something ;
do something ;; <--
esac

AngTheo789 03-15-2010 04:09 AM

As a matter of fact, I would even make a distinct function for the similar lines. That would make the code easier to read, maintain and to extend.


All times are GMT -5. The time now is 07:01 AM.