How can I create a nested screen session? - gnu-screen

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

Related

How open nested screen session with screen command linux

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

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?

how do you know your currently attached gnu screen session

We used gnu screen a lot in the office and sometimes if I don't take note, I end up getting lost as to what screen session I already am in.
So my question is, how do you know what screen session you're in? Do you have a way to check?
CLARIFICATION: What I need to know is when I do a:
~$ screen -ls
and I see something like:
There is a screen on:
4732.work_Sept42012 (Attached)
3551.web01 (Attached)
5521.mysql01 (Attached)
1255.tomcat05 (Detached)
3326.oracle15 (Attached)
1 Socket in /tmp/uscreens/S-icasimpan.
How do I know if I am currently connected to any of the attached session?
Thanks in advance.
In addition to the sessionname screen command, screen sets the STY environment variable for processes it starts. You can check the value of this variable from a shell:
$ echo $STY
5521.mysql01
$
Update:
ctrl+a, :sessionname can be used to display the name of the current screen session.
Previous reply (with missinterpreted question):
I struggled with this too until I came across the wonderful hardstatus feature. With these two lines in my ~/.screenrc I get the following at the bottom of my screen sessions.
hardstatus alwayslastline
hardstatus string '%{= kG}%-Lw%{= kW}%50> %n*%f %t%{= kG}%+Lw%< %{= kG}%-=%D %M %d | %C:%s %A %1`%{-}'
What I am looking at here is a screen session on my local computer with three windows (bash, mumble, kalkyl). In the active window called mumble I am connected to another computer over ssh on which I am running another screen session with three windows (top, auto, bash). I can see see all windows in both sessions and keep track of where I am.

Unable to understand two lines in .screenrc

I do not know how you can see the effects of following lines in your screen
bind ^g screen -t 'Google' links www.google.com
bind G screen -t 'Google' sudo -u insec links www.google.com
I tried unsuccessfully to press Ctrl-g at a word in a scrollback mode.
I also tried to search clickable words unsuccessfully in my manuals by
man man
How can you see the effects of the lines?
To try the bind ^g line, press Ctrl-A Ctrl-G.
To try the bind G line, press Ctrl-A Shift-G.
All those key bindings work inside screen if the bind lines are in $HOME/.screenrc and you have started screen after saving $HOME/.screenrc. To see if you have screen running, press Ctrl-A V (without shift). This will show you (in reverse color) the version number of screen at the bottom row in the window. If you don't get this information, you have to start screen first, by typing screen and pressing Enter.
The get more information about defining custom key bindings in GNU screen, please read the entry for bind in the CUSTOMIZATION section of the man page of screen.
you need to hit Ctrl-A then Ctrl-G.
it should create a new window that executes links (of course you must also have it installed) program to browse google in text mode.
Ctrl-A then G should run as user 'insec' and then run links again.

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"