I'm kind of new to bash scripting and I'm having trouble figuring out how to accomplish this.

I'm working on a script that is designed to backup and manage a java application that runs within a screen session. The goal is to be able to have multiple instances of the java application running on the different machines and to be able to control them over ssh from the script.

A feature I would like to have is the ability to easily call up the screen session of one of the java instances and display it to the user. So if the screen session is running on Machine A and I want to show it to the user on Machine B, I want to be able to initiate an ssh connection and call that up programmatically.

In short, I want to mimic the following user commands in a bash script:

ssh [email protected]
screen -r ScreenName  #Run from inside of ssh session

1 Answer 1


How about:

ssh user@host -t screen -r
  • Throws the error: Must be connected to a terminal. Commented Jul 5, 2014 at 1:38
  • 1
    @RileyTench use ssh user@host -t screen -r SCREENAME Commented Jul 5, 2014 at 1:39
  • Wow, that's perfect. For some reason I didn't think that would work, because usually sending a command like that, just executes the command on the remote host and doesn't return anything into the client's terminal. Thank you! Commented Jul 5, 2014 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .