screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatically start/attach to a multi-user Screen session, for new


From: David
Subject: Re: Automatically start/attach to a multi-user Screen session, for new BASH shell instances.
Date: Sun, 4 Oct 2009 18:38:00 -0500

I have a very similar setup...   It is so nice to be able to login directly at my computer, or SSH, or open an xterm, etc and always be placed inside a pre-existing screen session, able to access all my other screen windows.

Here are links to my .bashrc and .bash_login that I use to make this happen.   More of my notes are  http://tech.thedesignhut.net/screen


My code is not formatted the best.   I have a fair amount of comments along the way in each file, detailing the screen-related issues for dealing with logins that happen in situations like SCP and x-ming, and if x-windows is running from within screen and then you open a xterm w/in that, etc.

Took me lots of trial and error, am open to any input for improving those files.   They do work great currently.

The main screen session is "Cornerstone" (with one blank, non-writable window, has a message giving its purpose, and is held open with a long "sleep" command) and windows are titled by date & time.   In case two logins happen during the same minute or second, milliseconds is also used in the window name,  in order to make sure each window name is unique.

Looking through your e-mail...  perhaps I don't need to have the "Cornerstone" window held open all the time, it can recreated each time it's needed.   The names of the windows are quite long b/c they include the milliseconds;  I'd like them to be shorter because my .screenrc makes each window to be listed in the caption, and I can't see more than two window titles in my caption since each window title is so long -- BUT I still want to guarantee uniqueness of window titles.

In my script, the DISPLAY variable is intensionally imported into each screen window individually, this is necessary for x-ming (or X-over-SSH) to work.

-David




2009/9/30 Ryan Lynch <address@hidden>
I've set up my .bashrc to automatically attach me to a Screen session
when I open a new BASH shell (unless the env var $STY is set, or $TERM
contains 'screen', or the shell isn't interactive).  I have some
wrapper logic, but the basic algorithm is:

 * Always use '__DEFAULT' as a Screen session name.
 * Each new BASH shell / Screen window gets the logon date/time, as a
window title.
 * At logon, attach to a new window, in the existing Screen session
(if it exists) or in a newly-created session (if none exist, already).
    * Try to execute ('-X' opt) the command `eval "screen -t
$DATETIME" in an existing session named '__DEFAULT' (returns nozero,
if no such session).
    * If there is no existing session (previous command failed),
create a new, detached session ('-dm' opts), with a single window ('-t
$DATETIME' opt).
    * Attach as a multi-user ('-mRR' opts) to the now-existing
session '__DEFAULT', to the window '$DATETIME'.

This is pretty nice, for me--I don't have to remember to attach each
new BASH instance to a Screen session, every time I open a new tab in
'konsole' or logon via a VT or SSH.  But it feels kind of complicated,
to me.

Is there an easier way to do this?  I've included an abridged version
of my .bashrc, below, in case it's not clear from the description.  I
would be very interested in hearing from anyone else who has tried
anything similar:  What do you do, and how do you do it?

Thanks,
Ryan

Ryan B. Lynch
address@hidden


##### From .bashrc #####

# Some checks for the current BASH's interactive-ness, $TERM, and $STY.
# ...
# A short-timeout warning message that we're about to enter a Screen
session, or hit any key to drop into a normal BASH shell.
# ...

SCREEN_SESSION_NAME="__DEFAULT"
SCREEN_DATETIME="$(date +%Y%m%d_%H%M%S)"

# Add a new window, if a session already exists. If not, create a
window in a new, detached session.
if ! /usr/bin/screen -xRR "${SCREEN_SESSION_NAME}" -q -X eval "screen
-t ${SCREEN_DATETIME}"; then
   /usr/bin/screen -dmS "${SCREEN_SESSION_NAME}" -q -t ${SCREEN_DATETIME}
fi

# Co-operatively re-attch to whatever session, existing or created just now.
/usr/bin/screen -xRR "${SCREEN_SESSION_NAME}" -p ${SCREEN_DATETIME}

# A short-timeout warning message that we're about exit this BASH
shell, or hit any key to continue in it, instead.
# ...


_______________________________________________
screen-users mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/screen-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]