Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This is what my code looks like

master_script.sh

#!/bin/bash
chmod +x *
declare -A test=(
    ["echo1"]="sh `pwd`/echo1.sh"
    ["echo2"]="sh `pwd`/echo2.sh"
    ["echo3"]="sh `pwd`/echo3.sh")

log="$base_path"
for var in ${!test[@]}
do
    `${test[$var]} >> $var.log`
    echo "$var Started! :-)"
done

echoX.sh scripts looks like this

#!/bin/bash
while true;do
    echo "This is from Test1"
    #some Code
    echo "Eching the Output"
    #some other code!
    sleep 60
done

The idea is ok, but as you know, the control is waiting at ${test[$var]} >> $var.log. Each echoX.sh is while loop, So the control is waiting to complete!. I want to start ALL scripts

How can I resolve this issue?. NOTE: There are future planings implement features like, staring single script like

./master_script.sh start echo1, --> Will start only echo1

./master_script.sh stop echo1 ---> Will stop only echo1

./master_script.sh start all--> will starts all scripts

So, thats why I followed above procedure.

There are some other thoughts like.(Which don't want to do!)

echox.sh

#!/bin/bash
echo "This is from Test1"
#some Code
echo "Eching the Output"
#some other code!

nohup_echoX.sh

#!bin/bash
while true;do
  ./echoX.sh >> test.log 2>&1 &
done

Then in the mater_script.sh, ill add the ./nohup_echoX.sh in for loop.

So, is there any way to implement this. And more thing, I saw(ps aux | grep <NAME>), there are multiple instances of same process are running. So, how can I control this?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Change the line

`${test[$var]} >> $var.log`

to

"${test[$var]}" >> "$var.log" &
share|improve this answer

Gnu parallel will nicely allow you to run multiple processes from shell script in parallel, waiting for their completion.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.