shell - Go root, create tmux, send commands and then attach - all via a single SSH command in a bash script -


how go sending command via ssh:

ssh user@server -t 

which create tmux session, send commands , attach - allowing manually work on interactivity presented commands? has done while @ same time logging in root - not via sudo.

ssh user@server -t "bash -c \"su - -c \"tmux -d \; apt-get update \; apt-get upgrade\" root\"" 

or without bash -c (which attempt @ getting ssh show tmux window - (when using su - instead of sudo) not display shell. when running script - when run directly shell command there no issue.

another attempt have been:

ssh user@server -t "su - -c \"tmux new-session -n $session_name && tmux send-keys -t $session_name \"$command\"\" root" 

this latter work relatively - attaches tmux session , such commands sent after exiting tmux manually only.

the idea automatically create tmux session in commands run - , attach it. done part of bash script.

any ideas?

for interested, command found work was:

ssh -p22 user@server -t "su - root -c \"tmux -d $session_name\;\"-t $session_name -c \"apt-get update\"\" \; \"-t $session_name -c \"apt-get upgrade\"\"\"" 

however not make enter tmux - merely sends input tmux user. step in right direction not quite there..!

very open more efficient answers!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -