OpenWrt Forum Archive

Topic: running multiple script from shell at the same time

The content of this topic has been archived on 29 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Is it possible to run multiply scripts from shell?

if shell sript a.sh starts, shell script b.sh has to start at the exact time.
they have to run side by side.

example:
in shell script i wan't to run a ping test to www.google.com with the output written to a textfile.
in shell script i wan't to run a ping test to the dns server of google (8.8.8.8) with the output written to a textfile.

a.sh
#!/bin/bash
$(date +%Y%m%d%H%M) >> /mnt/pinga.txt
ping -c 10 www.google.com >> /mnt/pinga.txt

b.sh

#!/bin/bash
$(date +%Y%m%d%H%M) >> /mnt/pingb.txt
ping -c 10 8.8.8.8 >> /mnt/pingb.txt


both scripts are a simple example.
So, in my mean script (dualscript.sh) i do this:

#!/bin/bash
#######
script1=`/mnt/a.sh`
script2=`/mnt/b.sh`
#######
sh $script2 & sh $script1
done


dualscript.sh now first run a.sh when the script is done, then he starts b.sh.
but i don't want that. they have to start at the same time.
i found some related topics for running parallel scripts, but not for OPENWRT.
somebody can help me smile ?

Just start both scripts in the background and then wait till both pid's are finished
so it will be:

#!/bin/sh
#######
script1=`/mnt/a.sh`
script2=`/mnt/b.sh`
#######
"$script2"&
"$script1"&
wait

This way all child processes have to finish before the main script continues.
Also openwrt doesn't have bash, so if the scripts didn't run before that is the reason.

FriedZombie wrote:

Just start both scripts in the background and then wait till both pid's are finished

I think that is not the issue. I've just tried what he/she posted, and it works. As he/she said this were just examples, I'm guessing it's a mistake in the real scripts.

The discussion might have continued from here.