4

So I have a screen session running on one terminal/machine I would like to write a script that would attach to that screen session on another machine, but to a new window in that screen.

Does anyone know how I can do this? I feel like it might have somethig to do with screen -x (session name) -p (window number)...if i put "-" as the window number, it goes to a blank screen, but I want a fresh window.

EDIT: Not really looking for a solution anymore myself, a neat tool called "tmux" replaces screen and makes this all trivial.

6
  • If you start screen(1) on one machine, you can log out and retake the conection elsewhere. It even offers the possibility of opening seevral tty's and switch among them. Or do you mean something else?
    – vonbrand
    Commented Jan 22, 2013 at 19:18
  • @vonbrand The first machine must stay logged on
    – Justin L.
    Commented Jan 22, 2013 at 19:44
  • So what you really need is a way to share the screen (or at least some applications)?
    – vonbrand
    Commented Jan 22, 2013 at 19:56
  • @vonbrand I'm really asking for a way to share sessions. I already know how to do this, but I can't -x into a session without joining an already existing window or going to the window selection page.
    – Justin L.
    Commented Jan 22, 2013 at 20:11
  • Do you want the screen session to be interactive and run a command in a new window? Or just start the script in the new screen window without an interactive session?
    – George M
    Commented Jan 22, 2013 at 21:33

2 Answers 2

6

You can send send arbitrary screen commands to a session using the -X option.

For example, say you start one screen with the session name "test":

screen -S test

From another terminal (or over ssh), you can create a new window in the original screen session using the following command:

screen -S test -x -X screen

If you want to run something the in the new screen, you can do so by simply appending the command name to the end. For example:

screen -S test -x -X screen mutt

will run mutt in the new window. Be aware that this window will close immediately when the program exits, so won't be useful if you want to see the output of short-lived programs.

For more commands that can be sent using -X, search for "The following commands" in the screen manpage.

1
  • I just realized that I misread your question. The above solution will open a new window in the OLD screen. It sounds like you want to connect and then automatically open a window in the NEW screen (to avoid having to type C-a c immediately). I don't know how to do this, but it may be possible with -X.
    – kbeta
    Commented Jan 22, 2013 at 22:35
1

Here is the answer:

https://stackoverflow.com/questions/10599769/attach-to-screen-session-with-creating-a-new-screen-window

I was looking for the same thing

1
  • 1
    Hello and welcome to the Stack Exchange network :). Please try to sum up the information included in the link you provided so that readers know what to expect before they follow it.
    – Joseph R.
    Commented Oct 17, 2013 at 9:29

You must log in to answer this question.

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