This question already has answers here:
How do you run multiple programs in parallel from a bash script?
(19 answers)
Closed 6 years ago.
I have this bash script:
#!/bin/bash
for i in `seq 1 10`;
do
./Hysto file$i.txt
done
I am completely new to parallel programing and even bash language but i meant by this code to run 10 jobs in parallel (I have more than 10 cores available). The program in meant to save data to some files (which don't depend on each other). However in the folder where the files are supposed to be created they appear one by one (the output of file1.txt, then file2.txt and so on), so I assume they are not run in parallel. Can you tell me how can I write a bash file so I can run my jobs in parallel?
All you need to do to run in parallel in bash is to put an & at the end of your command. Here you'd put it after .txt.
See also: How do you run multiple programs in parallel from a bash script.
Related
This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
how to use variables with brace expansion [duplicate]
(2 answers)
Closed 2 years ago.
I have the following in my bash file:
echo "Spawning $1 processes"
for i in {1..$1}
do
(go run loadgen.go $2 &)
echo "done."
done
However, I can only seem to get my go file to execute once. I know that they're started in the background, but each of my go files should append to the same log file (I can reproduce this by running my bash script multiple times). Am I doing something wrong to get this to iterate multiple times?
This question already has answers here:
How do I run a shell script without using "sh" or "bash" commands?
(13 answers)
How to enable a system-wide function for users including sudo?
(2 answers)
Closed 3 years ago.
I have a bash script called climb.sh. When I execute it I write
./climb.sh 1
while inside the directory in which the script is located. However, I want to do the same thing wherever I am, and across all shell sessions by simply calling
climb 1
Also, climb.sh takes an numeric argument and calls "cd ../" that many times. In order for the program to work, it has to run alongside the current process, not within some child process.
How to achieve all this?
Thanks
This question already has answers here:
Loop background job
(3 answers)
Closed 4 years ago.
Is it possible to run a command in a for loop without waiting for that command ended, while keeping going to the next iteration?
Because I have to send multi-files at the same time asap via many ssh connections, therefore I couldn't wait until the command ended one by one.
Maybe is it related to something like 'xterm' or 'gnome-terminal'?
Yes, you can execute the command in background by adding & at its end.
So the syntax looks like programName [arguments] & (at least for bourne compatible shells)
This question already has answers here:
Global environment variables in a shell script
(7 answers)
Closed 5 years ago.
I'm working a small project which needs using OpenMPI to make "mpicc" work.
I made a file make_cmd:
#!/bin/bash
module load OpenMPI
However, after executing ./make_cmd, I was told:
mpicc: command not found
But if I just type on the command line: module load OpenMPI, then mpicc is working.
Why is that? Thanks!
See this answer on neighbouring site.
Because module is an alias/shell function and not a binary program, it's not necessarily available in the non-interactive sub-shell that is created when you run your script. You could probably run source make_cmd though, as that will just run the commands in your current interactive shell. You could ditch the #!/bin/bash line in that case.
This question already has an answer here:
Running several scripts in parallel bash script [duplicate]
(1 answer)
Closed 7 years ago.
I have the following shell script
#for i in {0..10}
do
run my command that takes about 10 seconds with parameter $i
done
How can I get this to run the commands in parallel without using GNU Parallel as I am not able to install it on my linux box.
Is there a way I can create 10 different shell scripts and call them e.g. script_1.sh, script_2.sh, script_3.sh etc and then launch them one by one from this script?
You could use an ampersand (&) and launch script.sh $1 & ten times. This will make the script run in a fork of the main process. It is an easy way to do parallel processing but definitely not very flexible and doesn't have many features. A simple tutorial can be found here.