For loop in parallel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop in parallel
# 1  
Old 10-10-2012
For loop in parallel

Hello,

My script shell is:

Code:
for i in $(seq $nb_lignes)

  do
 //command java
  done

Please, how can i execute all iteration in parallel ?



Thank you so much.

Last edited by Scrutinizer; 10-10-2012 at 03:35 PM.. Reason: code tags
# 2  
Old 10-10-2012
You can use threads. Since it's a java command that you want to run, you can write a small wrapper java program that calls the required methods and invoke threads that can run them in parallel. And you would want to rethink your strategy, if $nb_lines is going to be huge number!
# 3  
Old 10-10-2012
Code:
for i in $(seq $nb_lignes)
do
//command java   &
done
wait

This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 10-10-2012
i try

//command java &
done
wait

but i have a pb
each //command java is executed on a machine (i have 2 machines a and b and $nb_lignes=2)
i run the script on machine c , the fist iteration is well but i should do ctrl+c to pass to the second iteration or i want them in parallèll without doing ctrl+c

have you an idea please ?
# 5  
Old 10-10-2012
What do you mean you should do ctrl-c? What actually happens?
# 6  
Old 10-10-2012
Here is my problem:
Code:
for i in $(seq $nb_lignes) # a list of machines
do
 machine=`head $1 -n $i | tail -1`
ssh root@$machine -x "java ....."
done

i have three machines: A,B and C
"A " run the script
list of machines contain B and C
i'd like to execute java command in the two machines B and C , A display that B run the command only
And when i do ctrl+C it display that C run the command

Last edited by Corona688; 10-10-2012 at 01:26 PM..
# 7  
Old 10-10-2012
That sounds like the exact opposite of what you asked for before -- you want them to run in parallel, but you also want them to wait? Pick one.

Also, that is a horribly inefficient way of reading a file line by line...

Code:
while read LINE
do
        echo "line is $LINE"
done <$1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parallel increment of nested for loop

Hi, I am using solaris 5.10 environment and need help on doing parallel increment of nested for loop. Samples #inside the code the values assigned to a variable by another awk command will be like a=/xyz/pg/as /xyz/pg/as2 /xyz/pg/as3 b=/xyz/sd/fd1 /xyz/sd/fd2 /xyz/sd/fd3 for q in... (1 Reply)
Discussion started by: ananan
1 Replies

2. UNIX for Advanced & Expert Users

Trying to use a convoluted for loop with VLC and Parallel or OpenMPI with no success. Help?

I have about 12,000,000 mod files I'm trying to turn into a test of "unlimited cloud storage" by running them all through VLC and blowing them into mp3 files. I can get this to work serially but when trying to use openMPI or Parallel, something in the syntax is tripping it up some. Here is an... (1 Reply)
Discussion started by: sparticus414
1 Replies

3. Shell Programming and Scripting

Run script in parallel in while loop

Hi I am running a loop which actually runs same script for different argument value passed to it. while read repID do echo "Starting for $repID"; date; perl process_report.pl $repID done<${FILE_TO_READ} However this runs in sequence. I want the loop to not to wait for perl to... (3 Replies)
Discussion started by: dashing201
3 Replies

4. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

5. Shell Programming and Scripting

Run the for loop in parallel

I have the below code which runs on multiple databases , but this runs one-after-one. I will need this to run in parallel so that i could save a lot of time. Please help!!! Thanks in advance for Db in `cat /var/opt/oracle/oratab |egrep -v "ASM" |grep -v \# |cut -d\: -f1` do { export... (5 Replies)
Discussion started by: jjoy
5 Replies

6. UNIX for Dummies Questions & Answers

Need to test 100 ssh connections in parallel using loop and sleep? How to do that ?

Hello All, I want to test how much parallel ssh connections can be done on a server. I am thinking of reading username and hostname from a file and then using a loop (may be for) to do ssh on different host. Could anyone suggest me how can i write the script for the above. Thank you in... (0 Replies)
Discussion started by: ABHIKORIA
0 Replies

7. Shell Programming and Scripting

parallel while loop based on the file records

Hi, I need to execute parallel with while loop. Input File(source_file.csv) contains filenames the below source_file.csv file contains Customer1.txt Product1.txt Sales.txt Emp.txt Dept.txt Based on the number of rows that file I want to run the script ‘n' times. while... (2 Replies)
Discussion started by: onesuri
2 Replies

8. Shell Programming and Scripting

parallel processing

hi i am preparing a set of batches for a set of files sequentially There is a folder /xyz where all the files reside now all the files starting with 01 - will be appended for one below other to form a batch batch01 then all the files starting with 02 - will be appended for one below other to... (7 Replies)
Discussion started by: mad_man12
7 Replies

9. Shell Programming and Scripting

Execute commands parallel in a for loop ?

Hi, please can someone point me in the right direction with a shell scripting problem. I want to execute a command in a for loop and the command should be started not one-by-one meaning the for loop is waiting for the exit code , it should be started in parallel. I have a plain text file... (3 Replies)
Discussion started by: networkfre@k
3 Replies

10. UNIX for Dummies Questions & Answers

How to do parallel processing??

Hi All, I am working on solaris 8 sparc machine with 2 cpu. I am trying to run my application which generates files. I run multiple instance of the application, but the results don't seem to show as if it were runing parallely. When i run the application once it takes 12 secs to generate a... (1 Reply)
Discussion started by: zing
1 Replies
Login or Register to Ask a Question