I have seen some similar questions asked but the solutions don't seem to work in my case.
I am trying to SSH into a specific screen instance on a Node machine and then execute some commands
My current process is this:
On the remote machine I create a screen instance:
screen -dmS "my_screen"
ssh <user>@<remote> -a -x -t screen -x -r my_screen -X stuff 'ruby my_script.rb'
ssh <user>@<remote> -a -x -t screen -x -r my_screen
In your second example, you are executing the command by typing it into the console. If that is the behavior you want to emulate, you can use the
stuff command to have
screen paste your text into the console to execute it.
ssh <user>@<remote> -a -x -t screen -x -r my_screen -X stuff \"ruby my_script.rb^M\"
(Note the ^M was generated using CTRL-V, CTRL-M).
This won't display anything to your open terminal, but when you reconnect to the screen, you should see the output of your command (assuming the screen was at a console window at the time you sent the command, which is the risk with this approach).