Remove the semicolon from your example:
ssh example.com "screen -r"
However, you will not get a lot of bandwidth for this particular command, since a connected terminal is required to successfully complete this.
* EDIT 1 *
To run multiple commands, simply join them together, separating them with a comma:
ssh example.com "screen -r; ls -al; ps -elfc"
* EDIT 2 *
Still not quite sure what you are trying to accomplish (was screen -r
just an example, or are you really trying to just combine a bunch of commands together?). In any case, I am correcting my answer to cover more possibilities:
To combine arbitrary commands together:
ssh example.com "ps -elfc; ls"
To run some random commands after starting the screen:
ssh -t example.com "screen -r; ls"
To specifically launch the screen and send commands to it:
ssh -t example.com "screen -r -X ls"
source share