0

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?

0

Change the line

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

to

"${test[$var]}" >> "$var.log" &
4

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

0

I found Supervisord which is really cool. easy start, easy config, easy manage!. Check out this Blog to know how to use and config :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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