Run bash script from another script without waiting for script to finish executing?
Put &
at the end of the line.
./script1.sh & #this doesn't blocks!
./script2.sh
How to loop run an executable multiple time without waiting for it to finish
Bash executes foreground processes in a synchronous way. To do it as you want, you have to launch the process in the background using &
, as pointed out in the comments. You can make a function that implements the desired behavior for a file and then call it inside the loop.
The only problem with a separate asynchronous function, is that the counter
variable will not necessarily match your actual numbered filenames, so if you want them to keep the original number, you must extract it explicitly from the original name, or use an explicit variable. I will use the second approach in the following snippet:
#!/bin/bash
# Function to encapsulate your processing
# First arg: input file
# Second arg: counter
process_file(){
cd /some/dir/for/out/files/outputs/
mkdir file$2
cd file$2
/dir/where/executable/located/./run $1
}
for i in {0..65..1} # Iterate through the numbers, not the files, so we can use $i as a counter
do
input_file=/directory/where/input/files/are/file$i.txt
process_file $input_file $i & # Ampersand to launch in the background
done
Edit:
This is actually overkill for this case, as I'm pretty sure having you very same script, but with &
appended to your run
command, would do it. However, this approach is scalable in case you want to add more sequential processing for each single file and still have it in parallel for all files.
Bash Script Calls another bash script and waits for it to complete before proceeding
Normally it does; something else is happening. Are you sure that the other script isn't running something in the background instead? You can try using wait
regardless.
Parallelise a Shell script without waiting for a batch to finish
The desired queue behavior, (but not necessarily the CPU assigning), can be made to work with command grouping like so:
{ ./hello<params1.txt && ./hello<params3.txt ; } &
{ ./hello<params2.txt && ./hello<params4.txt ; }
Demo of something like the above:
{ { echo a && sleep 2 && echo b ; } &
{ echo c && sleep 1 && echo d ; } } | tr '\n' ' ' ; echo
Output:
a c d b
execute bash script from php without waiting
This has to work:
exec('/your/command /dev/null 2>/dev/null &');
Wait for .sh script to finish before executing another .sh script?
Simply use the &&
connector (i.e. a compound-command):
./script1.sh && ./script2.sh
But please consider that in this case the second script will be executed only if the first returns a 0 exit code (i.e. no error). If you want to execute the sequence whatever the result of the first script, simply go:
./script1.sh ; ./script2.sh
You can test the behaviour of the two connectors:
$ true && echo aa
aa
$ false && echo aa
$ false ; echo aa
aa
Related Topics
Why Is There No Directx API for Linux
Bluetoothctl to Hcitool Equivalent Commands
Bash: Add String to the End of the File Without Line Break
How to Find Out Mount/Partition a Directory or File Is On? (Linux Server)
Redirect All Output to File Using Bash on Linux
Exclude List of Files from Find
What's the Accepted Method for Deploying a Linux Application That Relies on Shared Libraries
How to Convert ".." in Path Names to Absolute Name in a Bash Script
Where Are the Stacks for the Other Threads Located in a Process Virtual Address Space
Linux Debian Crontab Job Not Executed
Cannot Install Docker in a Rhel Server
Gzip Multiple Files Individually and Keep the Original Files
How to Make Sure the Numpy Blas Libraries Are Available as Dynamically-Loadable Libraries
How to List the Size of Each File and Directory and Sort by Descending Size in Bash
What Does "Bash:No Job Control in This Shell" Mean
Remove Line of Text from Multiple Files in Linux
Bash Script to Detect When My Usb Is Plugged in and to Then Sync It with a Directory