[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Inherited Environment and Multi-attach
From: |
John Davidorff Pell |
Subject: |
Inherited Environment and Multi-attach |
Date: |
Sun, 27 Mar 2005 01:17:33 -0800 |
Re: screen and ssh agents + agent forwarding (+ $DISPLAY)
I'm replying to this old thread because it is something that I have
been working on for a while and have a good solution for.
Here's how I do things:
A)
I have a script [1] that starts screen in the background somewhere
(detached). This runs when I log in to my GUI (or when I run it
arbitrarily). :-)
My .screenrc starts at least one window, preferably one that I will
not ever close, like a tail on my console.log. This ensures that
screen doesn't ever exit. :-)
** Would it be a good idea to add an option to screen so that it does
*not* exit after the last command completes? **
B)
When I open a terminal window (xterm, Eterm, &c.) I have it set to
run an attach script [2] instead of a shell.
This script saves various variables to a file in my temp directory (I
use ~/.temp, I don't like storing this stuff in /tmp). It also adds
the path to this new file to the end of a file in ~/.screen, which I
call my stack.
It then attaches to screen.
Once screen exits (detaches), it removes the path to the environment
file from the stack. It does NOT just remove the last file in the
stack, but specifically the file that was created during this
particular attach. This creates a race condition, but is unlikely
ever to fail. (The race condition is if I log in and accesses the
stack at the same time, possibley damaging it by concurrent writes;
also happens with two simultaneous logins, though less so because I
just append to the file instead of overwriting it.)
C)
Another script [3] is sourced before every prompt (PROMPT_COMMAND).
This reads the most-recent environment file (saved by [2]), as
determined by the last line in the stack file.
D) That's it!
This means that if I log in at home, and leave my screen attached,
then log in at work, my work variables (like DISPLAY or
SSH_AUTH_SOCK) are set properly. When I log out from work, my home
variables are at the top of the stack, and so they also get restored
as soon as I press enter at home.
Even better: If I log in at home, then log in at work, then log in on
my laptop, then log out from work, my home variables will be properly
restored when I get home (after I have logged out from my laptop).
BUG: If I log in at home, then at work, then on my laptop, then go
home my laptop variables are still set. If I then logout from my
laptop, my work variables become set.
Solution: Re-attach at home, and it becomes the most recent session
on the stack. :-)
Comments and Suggestions wanted!!
JP
P.S. My scripts make assumptions about the system they're on.
Portability fixes definitely welcome!
[1] http://homepage.mac.com/johnpell/2005March26/Screen.sh
[2] http://homepage.mac.com/johnpell/2005March26/screenAppAttach.sh
[3] http://homepage.mac.com/johnpell/2005March26/screenenv.sh
- Inherited Environment and Multi-attach,
John Davidorff Pell <=