1

I'd like to run some different scripts simultanously using bash. All of them say something to an screen-session.

What we have:

worker=1

while [[ ! -f "worker$worker.sh" ]]; do
if [[ ! -f "worker$worker.sh" ]]; then

cat >worker$worker.sh <<EOL

#some code with variables which change and say something to an screen session#

EOL

chmod a+x worker$worker.sh 
./worker$worker.sh
break
else
(( worker ++ ))
continue
fi
done

The current code does not work :/ What's wrong?

4
  • 2
    I suggest to take a look at GNU parallel. Commented Apr 10, 2017 at 18:46
  • @Cyrus I'll check this out, thx. Commented Apr 10, 2017 at 18:47
  • Welcome to stackoverflow! Consider including a description of what you expected to happen and then a description of what actually happens (including any commands you run and what they output). It's especially helpful if people can see the same behavior by running your posted script themselves (instead of you running a different/full version and then reporting on what that does without letting anyone see the code) Commented Apr 10, 2017 at 18:53
  • Please add a simple example of "saying something to a screen session". Commented Apr 10, 2017 at 21:31

1 Answer 1

3

tmux is an alternative to screen.

GNU Parallel has an interface to tmux, so try this:

parallel --fg --delay 0.1 --tmuxpane ::: worker*.sh
parallel --fg --delay 0.1 --tmux ::: worker*.sh

If you do not need the tmux interface:

parallel ::: worker*.sh

Start by watching the intro videos for a quick introduction: http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Then look at the EXAMPLEs after the list of OPTIONS (Use LESS=+/EXAMPLE: man parallel). That will give you an idea of what GNU parallel is capable of.

Then spend an hour walking through the tutorial (man parallel_tutorial). Your command line will love you for it.

Sign up to request clarification or add additional context in comments.

2 Comments

I have never seen GNU Parallel used with tmux! I tried a simple example and it says Can't join a pane to its own window? I just did parallel --fg --tmuxpane 'echo {}; sleep 3' ::: 4 5 6 7
Yeah. You experience a race condition. Add --delay 0.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.