How open nested screen session with screen command linux - gnu-screen

I want to open multiple sessions in one main session with a screen command, and I can do that after opening the main session and then press on the keyboard (CTRL + A + c) but I don't want this way I want to do this using the command line only because I create a script to open the main session with multiple sub-session, so how can I achieve this. And thanks in advance :)

CTRL+A+C doesn't create a new screen session. It creates a new window within the current session.
(With a little environment trickery, you could create a nested screen session within an existing screen session, where the outer screen session and the inner screen session could each have multiple windows, but that's probably not what you want to do.)
Each window within a screen session runs a command. By default, that command is your login shell. Thus you can have multiple shell processes running simultaneously and switch between them.
From any of those shells, you can create a new window under the current screen session using the screen command. It uses the $STY environment variable to recognize that it's inside an existing session, which tells it to create a new window rather than starting a new session. You could also type, for example, screen vi to launch a new window running the vi editor.
All this is covered in the screen documentation (info screen or man screen).
(Personally, I used screen for a long time, but then switched to tmux, which I find to be more flexible, more powerful, and easier to control from the command line. If you haven't invested a lot of time learning screen, you might consider switching. Or not; it's up to you, of course.)

You can do this using by by putting the following in your ~/.screenrc (or using a custom .screenrc file):
$ cat ~/tmp/screenrc_custom
...
<content of ~/.screenrc>
...
screen -t csh 0
screen -t csh 1
screen -t csh 2
$ screen -c ~/tmp/screenrc_custom

Related

SSH screen: how to back to the original window after Ctrl+a+c?

I'm running codes in session run. When I'm at this session, I occasionally create a new window by Ctrl-a c (in fact, I want to use Ctrl-a d to detach this session). Then I use Ctrl-a d to detach the session. But when I tried to enter the session run again to check the running progress using screen -r run, I found that I couldn't enter the initial session which runs my codes, instead, entered the created new window in which nothing runs. The screen -ls shows only one session named run. But top shows that all commands are still running. How can I enter the initial session run which runs my codes?

Scripting GNU screen

I've been trying to come to terms with scripting in GNU Screen. Upon reading the man pages and a few other examples, I understand that we can use the at command or the -X argument for sending commands to screen sessions.
Let me explain my situation. I need to write a script that runs from with in an existing screen session. This script should create new windows, set their titles, browse to a specific directory and run a program in each of these windows.
The problem with the at command is that I can only send one command at a time. When I create a new window using at command, it will not be possible for me to obtain the window number of that newly created window. Because of this, I will not be able to send any more commands to that new window. How can I retrieve the window number of this new window?
On creating a new screen window you can specify a name with -t (e.g. -t test) and send commands via -Xto this specific screen by using the additional parameter -p (e.g. screen -p test -X eval 'yourcommand --yourparameter')

How can I create a nested screen session?

What do I need to put in my .screenrc so that I can create nested sessions (ie: a screen within a screen)?
At the moment, if I run screen again from within an open screen tab, instead of opening a new screen session within that tab, it just opens a new tab (ie: same effect as if I had pressed -C)
I want to get an outer screen session and an inner screen session - How do I do this please?
My .screenrc is empty except for the following single line to show the list of open tabs:
hardstatus alwayslastline "%{=w}%{G} %{b}%w"
This is a very old question, but for reference:
Start a MAIN screen session:
screen -S main
Start a second session (detached):
screen -dmS SomeName
From the tab you want nested session:
screen -r SomeName
Use and extra a for commands to nested screen, i.e. ^a-a-c to create a tab in the nested screen.
Don't know if what you mean is to start some nested sessions from your screenrc or to set something in your screenrc so you can start nested sessions from the colon prompt.
For the first, I use a separate screenrc file, .screenrc.main, which contains
source ~/.screenrc
screen -t <window name> screen -S <nested session name> -e^jj <command>
I think the "new session name" part is necessary to get a new session. I use a different command character for the nested sessions. Also I am using a separate file because I don't want the command to be executed for the nested sessions. Then from command line I do
DISPLAY= screen -S <top session name> -c .screenrc.main
to start the outer session.
For the second, I just type in the screen -t line above in the colon prompt.
From what I read in your question, it seems that you may be confused how to operate the nested session?
CTRL+a c will create a new 'tab' in the outer screen session.
CTRL+a a c will create a new 'tab' in the session 1 deeper than the previous
CTRL+a a a c creates a new tab in the session 1 deeper than the previous
I have had situation with 3 layers, where I SSH into my work box, then from there into a proxy and from there onto the server I want to work on, each time opening a screen session to be able to resume later.
Without a hardstatus showing the full hostname, it is very easy to get lost, very easy indeed!
I don't know about editing your screenrc file, but what works for me is sshing into the same computer then starting a new screen instance. Hackish workaround, but it does work...
screen
ssh 127.0.0.1
screen

Detach and reattach a complete Screen session with multiple windows

I am writing a client/server-application and when I'm testing the code I want to be able to have both the server and client in a separate terminal (+ vim). For this I thought I could use GNU Screen and divide the terminal in multiple windows (and it works great!). But I have a problem when I want to detach the whole session with windows and all. When I try to reattach the session I don't get them in windows like I arranged it, but instead they attaches like "normal" screen instances.
Also, is there a way to change the size of a screen window? Like change the height proportions of two windows splitted vertically.
your first question isn't possible because the regions (the way the windows are displayed) are bound to a single screen instance and not to a screen session.
C-a :
resize
see man screen for more explanation of the resize command

multi tabbed SSH client using screen

Is there an SSH client that can present a client side GUI interface to the screen* program?
I'm thinking of an SSH program that would hook in with screen's session handling and map client side actions (clicking on a tab, ctrl-tab, scrolling, possibly even allowing several tabs to be seen at the same time) to whatever it takes to make screen at the other end do it's thing.
* The screen program that allow multiple virtual consoles under a single terminal session, for example you can run several apps under a single SSH connection and switch between them as well as other cool things.
An interesting idea, and quite possible (vim7's tabs show as clicky GUI tabs in gnome-terminal), but I don't see the benefit of doing this..
Using the follow ~/.screenrc shows "graphical" tabs:
startup_message off
vbell off
hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}]%{=y C}[%d/%m %c]%{W}'
..which look like the following (after renaming the tabs using ctrl+a,a:
x http://img216.imageshack.us/img216/9401/picture4myi.png
You can scroll around in a screen session using "copy mode", by doing ctrl+a,[ and using the cursor keys (press Esc or ctrl+c to exit it)
You can also attach to the same screen session multiple times using the screen -x flag (rather than -r), so you could use any tabbed terminal emulator, and open one tab for each screen-window.
If you really did want to start implementing this - one option would be to look into modifying gnome-terminal, to copy the behaviour with vim's tabs for screen. Or, write your own screen client - you don't need to do anything as fragile sounding as scraping the terminal - there's a FIFO file in (usually) /tmp/uscreens/S-$USER/$PID.sessionname which I think is how screen communicates, and remember screen is open-source!
Interesting idea. I use screen everyday both on my local machine and for SSH sessions. I think your biggest problem is that I suspect most screen users are commandline junkies like me who just won't see the benefit of making a gui for tabs. In fact, I have all my terminals in one gnome-terminal window under different tabs, and having screen's text-based tabs is a nice way not to confuse the two.
I suspect it could be done, but you'd be writing a specialised terminal emulator which analyses screen's output (custom .screenrc) and retrofits the gui.
A lot of work for minimal gain.
ctrl+a shift+'
.. gui front-end to screen? what are you talking about??
also, because my rep is so low, and i cant comment, id like to LOL # geoffc for his comment in the question
I've never seen one, but the following may help you. Add to your .screenrc
To show a row of "tabs" on the bottom
caption always "%{.bW}%-Lw%{.rW}%n %t%{-}%+Lw %=%{..G} %{..Y} %m/%d"
To show the current program as the screen name [assuming you're using bash and your prompt ends with "$ " by default; others shells are the exact same idea]
shelltitle "$ |sh"