run serveral loops simultaneously?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting run serveral loops simultaneously?
# 1  
Old 01-22-2009
run serveral loops simultaneously?

Hello everyone, say I have the following script, which contains serveral loops, if I run the script, it executes the loop one by one (after the a loop, it goes to b loop, then c, then d)

I figured I should be able to run all the loops at same time, but I don't know how, can anyone help a little bit here? thanks!

for file in `ls a*`; do commanda ; done

for file in `ls b*`; do commandb ; done

for file in `ls c*`; do commandc ; done

for file in `ls d*`; do commandd ; done
# 2  
Old 01-22-2009
The best location for advanced topics! Special Characters

Anyways, that link will show you, but here is the code:

Code:
for i in 1 2 3 4 5 6 7 8 9 10            # First loop.
do
  echo -n "$i "
done & # Run this loop in background.
       # Will sometimes execute after second loop.



That will allow you to put the loop in the background (notice the & after done).
That should work!
# 3  
Old 01-22-2009
Quote:
Originally Posted by fedora
Hello everyone, say I have the following script, which contains serveral loops, if I run the script, it executes the loop one by one (after the a loop, it goes to b loop, then c, then d)

I figured I should be able to run all the loops at same time, but I don't know how, can anyone help a little bit here? thanks!

for file in `ls a*`; do commanda ; done

for file in `ls b*`; do commandb ; done

for file in `ls c*`; do commandc ; done

for file in `ls d*`; do commandd ; done

Not only is ls unnecessary, but it will break your script if any of the filenames contain spaces.

Code:
for file in a*; do commanda ; done &
for file in b*; do commandb ; done &
for file in c*; do commandc ; done &
for file in d*; do commandd ; done &

Or:

Code:
for l in a b c d
do
   for file in "$l"*; do command$l; done *
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run feeding each other processes simultaneously?

Hello, I need to run multiple shell processes simultaneously and output of the first process shall be the input of the second process but first process is never ending so both should be running in parallel. I do not wish to wait the end of the first process. I am under ubuntu 16.04. ... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

3. Shell Programming and Scripting

Run 2 shell scripts simultaneously from one script

i Run 2 scripts on all of around 50 nodes every day. 1.Mod_1.sh 2.Mod_2.sh eg.. i run file with specific node no like Mod_1.sh NODE_(node number) Mod_2.sh NODE_(node number) I want to run both file by using single script with unique node number. Eg.. Mod_new.sh NODE_(node... (11 Replies)
Discussion started by: Ganesh Mankar
11 Replies

4. Programming

Run two CGIs simultaneously and Ajax to read updated value from CGI1

Flow of program: C based CGI is used CGI1: -Gets called when user hits upload button(submit) ie form action = CGI1 -Does the file upload (copy to a directory etc) JS, Ajax fucntion: -A JS function is called when user hits upload button -The JS function opens an Ajax request for CGI2... (8 Replies)
Discussion started by: xs2punit
8 Replies

5. Shell Programming and Scripting

[Help] script how to run 2 commands simultaneously

#!/bin/sh firefox index.html firefox secondpage.html hey guys, im not able to open up two pages at the same time... it always open up index.html first, and only after i close it, then the 2nd page pops up... is there any way i can run both commands at the same time? i appreciate any... (2 Replies)
Discussion started by: funnyguy123
2 Replies

6. Shell Programming and Scripting

Looping through 2 files simultaneously

Hi all, I'm having a problem with a script which should ultimately provide a filename by reading a value from file1 and file2 then join together. I'm planning to use a loop/ loops to get the values out of both files and create a single string unfortunately the code currently treats the second... (7 Replies)
Discussion started by: chris01010
7 Replies

7. Shell Programming and Scripting

shell script - ftp downloading serveral files without mget

Hello guys, i'm searching for a solution how to download all files from root-directory of an ftp-server through an ftp proxy getting through the ftp proxy and download one file with get ist no problem, but mget * does nothing! ftp -n -i -v <<EOF open proxyHost proxyPort user... (19 Replies)
Discussion started by: macProgger23
19 Replies

8. Shell Programming and Scripting

read contents of a file with serveral lines & assign it to a variable

Hi All I have a file for ex .log file which contain several lines within it. I have to read that file contents & assing that to a variable. (2 Replies)
Discussion started by: satyam.sumit
2 Replies

9. Shell Programming and Scripting

Run a command in bg simultaneously with

Hi, I want to run the command below in the background: tail -f file.txt | grep "pattern" The file file.txt will start getting its contents written after this command has started getting run. So the flow will be like this tail -f file.txt | grep "pattern" #The line below will write data... (0 Replies)
Discussion started by: King Nothing
0 Replies

10. Filesystems, Disks and Memory

Running 2 Drives simultaneously?

So I have yet another query which requires the genius of the users on Unix.com. Having asked around at my work (Tech company) No one can really answer my question thoroughly. My goal is to get 2 Hard drives running at the same time and allow me to switch between working on one to the other.... (4 Replies)
Discussion started by: Infidel
4 Replies
Login or Register to Ask a Question