Run a shell script in a loop with max number of threads


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run a shell script in a loop with max number of threads
# 1  
Old 08-16-2018
Run a shell script in a loop with max number of threads

hi guys. i have a question for you

i have a one file and inside this file there are 1000 lines and each line is a linux command

running this commands takes long time so i want to create one bash script and run this lines in a loop with max number of threads

for example i want to run only 5 lines from this file once one of this command finished run the next (6th) command in a loop. how can i do that?

Thanks in advance
# 2  
Old 08-17-2018
Welcome to the forum.


Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, directory structures, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.




I'm afraid you can't create threads with shell means, but processes, and you should not expect too much performancewise when the processes you run in parallel compete for system resources.


There are several threads in these fora dealing with "parallel execution"; try searching for those. Or try sth. along this line (recent shell like bash needed):
Code:
while read CMD; do . <(echo "$CMD") & (( ++CNT%5 )) && wait; done < file




EDIT: MadeInGermany showed an interesting approach here
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Old 08-17-2018
thank you so much
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Display number from 10 to 1 using shell programming in while loop

display number from 10 to 1 using shell programming in while loop and using read n numbers (2 Replies)
Discussion started by: aswin
2 Replies

3. Homework & Coursework Questions

Display number from 10 to 1 using shell programming in while loop

echo "enter the number" read n while do echo "$n" let n-- done (1 Reply)
Discussion started by: aswin
1 Replies

4. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

5. Shell Programming and Scripting

ksh script to test max number of parallel ssh connections

hello , I need to check how many parallel ssh connections my server can take the load of. I need to login to different host which i am planning to read from a file and then a write a loop which will do parallel ssh. Please provide suggestion on how i can write script for the same.\ Thank... (1 Reply)
Discussion started by: ABHIKORIA
1 Replies

6. Shell Programming and Scripting

How do I run a shell command in a while loop?

The command is: sic -h irc.freenode.net 2>&1 | tee -a irc.log Where sic is an IRC client, and I'm piping the output to tee in order to log my IRC sessions. I'm trying to handle reconnects by running it in a while loop in the shell process and cat the initial commands into sic's stdin. I... (1 Reply)
Discussion started by: guitarscn
1 Replies

7. Shell Programming and Scripting

Multiple Threads/Tasks to run parallely using the shell script

Scenario: I have two PCs (named as A & B) which would send some traps to my third PC (named as C). In PC C, I have to write a shell script such that it should accept the datas from both the PC-A & B parallely. So my question is, is it possible to have two different child threads/tasks... (2 Replies)
Discussion started by: nthiruvenkatam
2 Replies

8. Shell Programming and Scripting

Threads in Unix shell script

I need to run two different sql queries using two different threads in the same Unix shell script. I did not understand what do we mean by creating two different threads. Does it mean two different statements containing SQL queires in that unix script? (1 Reply)
Discussion started by: kum5256
1 Replies

9. Shell Programming and Scripting

Max number of parameters to korn shell?

Hi All, what is the maximum limit for the command line arguments in korn shell. Regards, Raju (4 Replies)
Discussion started by: rajus19
4 Replies
Login or Register to Ask a Question