For loop and running 2 commands at once?

HI.

I am trying to run 2 commands, using the "for x in a b c d" loop but i am having a hard time coding it...

Here is what i have so far:

for SERVER in SERVERA SERVERB SERVERC SERVERD SERVERE 
do

###############################################################################
# Launching the first backup...
###############################################################################

        echo ${LOGIN} "GENERATE BACKUPSET ${SERVER}

###############################################################################
# Launching the second backup
###############################################################################

        echo ${LOGIN} "GENERATE BACKUPSET ${SERVER}

###############################################################################
# Waiting for the first pair to complete...
###############################################################################

  while (( $( ${LOGIN} q proc | grep "GENERATE BACKUPSET" | wc -l) != 0 ))
  do
     echo ".\c"
     sleep 60
  done
done

What i am trying to do, is get the loop to run the GENERATE BACKUPSET SERVERA and SERVERB at the same time. Then wait using the while loop at the bottom. Once those 2 are completed (while loop would exit) it should keep going to GENERATE BACKUPSET SERVERC and SERVERD and so on...I've inserted "echo" in the front for debug purposes...

What i am getting though, is a GENERATE BACKUPSET SERVERA twice instead...

I tried to issue a "continue" but that did not work either...

Ideas?

Thanks!

Start backup in background and wait process exit. Something like:

#!/ksh93 or bash or zsh ...
backup1=( SA SC SE )
backup2=( SB SD SF )
round=0
roundmax=${#backup1[*]}
while (( round < roundmax ))
do
       backup "${backup1[$round]}" &
       pid1=$!
       backup "${backup2[$round]}" &
       pid2=$!
       wait $pid1
       wait $pid2
       echo done 
       ((round+=1))
done

Thanks for the input.

I am getting some problems with this though...

Variables backup1 and backup2 with the ( ) does not work. I tried to use " but not good either...

I understand what your scripts tries to do and it seems logical, but can't figure out how to get it to work though...

Thanks.

Hi stephen,

Script posted by kshji itself working fine.If you face problems with assigning values to an array.Then,assign the values to an array using the following way.

i=0

for x in SA SC SE
do
backup1[$i]=$x
let i=i+1
done
i=0
for x in SB SD SF
do
backup2[$i]=$x
let i=i+1
done
for((x=0;x<$i;x++)) #This is for checking and printing the array values
do
echo "Back Up1 Values:${backup1[$x]}"
echo "Back Up2 Values:${backup2[$x]}"
done

Sorry, my term "posixsh" is not good in this case. This kind of array init is not in posix defination.
Many of current sh support it. Like ksh93, bash, zsh, ... but not in dash which is posix-sh without extension.

Thank you both for the explanation. Also, thanks for the example, i think i can get that to work.