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.
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: