4

Basically I want to write some script like

#!/bin/bash
for idx in 1 2 3 4 5 6
do
        ssh machine$idx tmux new-session -d -s "myTempSession$idx" python run.py
done

which can do the thing separately on each machine as:

ssh machine$idx 

tmux new-session -d -s "myTempSession$idx"

python run.py

but after many trial and error, I still cannot make it work as expected.

K.Wanter
  • 848
  • 2
  • 8
  • 16
  • 1
    Works fine for me. You might want to share a bit more detail of what goes wrong. Remember the classical problem report schema: action - expected result - actual result – Tilman Jun 28 '18 at 12:38

1 Answers1

3

You should divide the two actions 1) create a tmux detached session; 2) send a command/keys to it. Also maybe adding the -n option is a good idea... So your script should look like as:

#!/bin/bash
for idx in 1 2 3 4 5 6
do
    ssh -n machine$idx 'tmux new-session -d -s "myTempSession$idx"; tmux send-keys -t "myTempSession$idx" "python run.py" ENTER'
done
pa4080
  • 29,831