Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jan 22 '13 at 19:18
    
@vonbrand The first machine must stay logged on –  Justin L. Jan 22 '13 at 19:44
    
So what you really need is a way to share the screen (or at least some applications)? –  vonbrand Jan 22 '13 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. Jan 22 '13 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? –  uther Jan 22 '13 at 21:33

2 Answers 2

up vote 1 down vote accepted

Here is the answer:

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

I was looking for the same thing

share|improve this answer
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. Oct 17 '13 at 9:29

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.

share|improve this answer
    
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 Jan 22 '13 at 22:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.