How to write in bash to ssh to different machine and create tmux session then run some command in it

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Basically I want to write some script like
#!/bin/bash
for idx in 1 2 3 4 5 6
do
echo machine$idx
ssh machine$idx tmux new-session -d -s "myTempSession$idx" python run.py
done
which can do the thing separately 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.
UPDATE following Tagwint's advice, my script is:
#!/bin/bash
for idx in 1 2 3 4 5 6
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
but it prompts:
./dist_run.sh: line 8: warning: here-document at line 4 delimited by end-of-file (wanted `REMSH')
./dist_run.sh: line 9: syntax error: unexpected end of file
UPDATE I modify it to be
#!/bin/bash
for idx in 36 37
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
this works, but after run the script, I log into machine36 and machine37, go into the opened myTempSession, the python run.py is not executed
ssh scripting tmux
add a comment |Â
up vote
0
down vote
favorite
Basically I want to write some script like
#!/bin/bash
for idx in 1 2 3 4 5 6
do
echo machine$idx
ssh machine$idx tmux new-session -d -s "myTempSession$idx" python run.py
done
which can do the thing separately 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.
UPDATE following Tagwint's advice, my script is:
#!/bin/bash
for idx in 1 2 3 4 5 6
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
but it prompts:
./dist_run.sh: line 8: warning: here-document at line 4 delimited by end-of-file (wanted `REMSH')
./dist_run.sh: line 9: syntax error: unexpected end of file
UPDATE I modify it to be
#!/bin/bash
for idx in 36 37
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
this works, but after run the script, I log into machine36 and machine37, go into the opened myTempSession, the python run.py is not executed
ssh scripting tmux
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Basically I want to write some script like
#!/bin/bash
for idx in 1 2 3 4 5 6
do
echo machine$idx
ssh machine$idx tmux new-session -d -s "myTempSession$idx" python run.py
done
which can do the thing separately 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.
UPDATE following Tagwint's advice, my script is:
#!/bin/bash
for idx in 1 2 3 4 5 6
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
but it prompts:
./dist_run.sh: line 8: warning: here-document at line 4 delimited by end-of-file (wanted `REMSH')
./dist_run.sh: line 9: syntax error: unexpected end of file
UPDATE I modify it to be
#!/bin/bash
for idx in 36 37
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
this works, but after run the script, I log into machine36 and machine37, go into the opened myTempSession, the python run.py is not executed
ssh scripting tmux
Basically I want to write some script like
#!/bin/bash
for idx in 1 2 3 4 5 6
do
echo machine$idx
ssh machine$idx tmux new-session -d -s "myTempSession$idx" python run.py
done
which can do the thing separately 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.
UPDATE following Tagwint's advice, my script is:
#!/bin/bash
for idx in 1 2 3 4 5 6
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
but it prompts:
./dist_run.sh: line 8: warning: here-document at line 4 delimited by end-of-file (wanted `REMSH')
./dist_run.sh: line 9: syntax error: unexpected end of file
UPDATE I modify it to be
#!/bin/bash
for idx in 36 37
do
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession"
tmux send-keys -t -s "myTempSession" python Space run.py C-m
REMSH
done
this works, but after run the script, I log into machine36 and machine37, go into the opened myTempSession, the python run.py is not executed
ssh scripting tmux
edited Jun 28 at 11:58
asked Jun 28 at 9:52
K.Wanter
1204
1204
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I'd suggest you HERE-DOC apporach
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession$idx"
tmux send-keys -t "myTempSession$idx" python Space run.py C-m
REMSH
Note $idx part in session name will most probably resolve in nothing
unless you have a idx environment variable defined
so you'll get session name just myTempSession
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know howpython run.pyshould look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,py
â Tagwint
Jun 28 at 12:35
I guess in thesend-keys -t -s "myTempSession"line you should remove -s. Make it looksend-keys -t "myTempSession" ......that's copy/paste typo ), I'll update my answer above
â Tagwint
Jun 28 at 12:41
I finally make it work as :tmux new-session -d -s "launch_train" ; send-keys "python run.py
â K.Wanter
Jun 29 at 5:15
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I'd suggest you HERE-DOC apporach
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession$idx"
tmux send-keys -t "myTempSession$idx" python Space run.py C-m
REMSH
Note $idx part in session name will most probably resolve in nothing
unless you have a idx environment variable defined
so you'll get session name just myTempSession
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know howpython run.pyshould look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,py
â Tagwint
Jun 28 at 12:35
I guess in thesend-keys -t -s "myTempSession"line you should remove -s. Make it looksend-keys -t "myTempSession" ......that's copy/paste typo ), I'll update my answer above
â Tagwint
Jun 28 at 12:41
I finally make it work as :tmux new-session -d -s "launch_train" ; send-keys "python run.py
â K.Wanter
Jun 29 at 5:15
add a comment |Â
up vote
0
down vote
accepted
I'd suggest you HERE-DOC apporach
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession$idx"
tmux send-keys -t "myTempSession$idx" python Space run.py C-m
REMSH
Note $idx part in session name will most probably resolve in nothing
unless you have a idx environment variable defined
so you'll get session name just myTempSession
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know howpython run.pyshould look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,py
â Tagwint
Jun 28 at 12:35
I guess in thesend-keys -t -s "myTempSession"line you should remove -s. Make it looksend-keys -t "myTempSession" ......that's copy/paste typo ), I'll update my answer above
â Tagwint
Jun 28 at 12:41
I finally make it work as :tmux new-session -d -s "launch_train" ; send-keys "python run.py
â K.Wanter
Jun 29 at 5:15
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I'd suggest you HERE-DOC apporach
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession$idx"
tmux send-keys -t "myTempSession$idx" python Space run.py C-m
REMSH
Note $idx part in session name will most probably resolve in nothing
unless you have a idx environment variable defined
so you'll get session name just myTempSession
I'd suggest you HERE-DOC apporach
ssh machine$idx <<REMSH
tmux new-session -d -s "myTempSession$idx"
tmux send-keys -t "myTempSession$idx" python Space run.py C-m
REMSH
Note $idx part in session name will most probably resolve in nothing
unless you have a idx environment variable defined
so you'll get session name just myTempSession
edited Jun 28 at 12:42
answered Jun 28 at 11:20
Tagwint
1,3201612
1,3201612
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know howpython run.pyshould look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,py
â Tagwint
Jun 28 at 12:35
I guess in thesend-keys -t -s "myTempSession"line you should remove -s. Make it looksend-keys -t "myTempSession" ......that's copy/paste typo ), I'll update my answer above
â Tagwint
Jun 28 at 12:41
I finally make it work as :tmux new-session -d -s "launch_train" ; send-keys "python run.py
â K.Wanter
Jun 29 at 5:15
add a comment |Â
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know howpython run.pyshould look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,py
â Tagwint
Jun 28 at 12:35
I guess in thesend-keys -t -s "myTempSession"line you should remove -s. Make it looksend-keys -t "myTempSession" ......that's copy/paste typo ), I'll update my answer above
â Tagwint
Jun 28 at 12:41
I finally make it work as :tmux new-session -d -s "launch_train" ; send-keys "python run.py
â K.Wanter
Jun 29 at 5:15
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
thank you, @Tagwint pls see my update, there is maybe some typos
â K.Wanter
Jun 28 at 11:40
HERE-DOC is picky about indentations, so you did it right. I dont know how
python run.py should look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,pyâ Tagwint
Jun 28 at 12:35
HERE-DOC is picky about indentations, so you did it right. I dont know how
python run.py should look like to prove it is executed Any errors shown? Either python or run.py may just not be visible. My first guess is - Try adding /full/path/to/python and /full/path/toyour/run,pyâ Tagwint
Jun 28 at 12:35
I guess in the
send-keys -t -s "myTempSession" line you should remove -s. Make it look send-keys -t "myTempSession" ...... that's copy/paste typo ), I'll update my answer aboveâ Tagwint
Jun 28 at 12:41
I guess in the
send-keys -t -s "myTempSession" line you should remove -s. Make it look send-keys -t "myTempSession" ...... that's copy/paste typo ), I'll update my answer aboveâ Tagwint
Jun 28 at 12:41
I finally make it work as :
tmux new-session -d -s "launch_train" ; send-keys "python run.pyâ K.Wanter
Jun 29 at 5:15
I finally make it work as :
tmux new-session -d -s "launch_train" ; send-keys "python run.pyâ K.Wanter
Jun 29 at 5:15
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452394%2fhow-to-write-in-bash-to-ssh-to-different-machine-and-create-tmux-session-then-ru%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password