[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reattaching to a detached screen
From: |
Trent W. Buck |
Subject: |
Re: Reattaching to a detached screen |
Date: |
Fri, 02 Jan 2009 01:26:13 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Andrew Schulman
<address@hidden> writes:
>> autossh -M 0 -t RemotePC "screen -e^Yy -D -R -S `uname -n`2RemotePC-$NEXT"
> <snip>
>> What I would like to be able to do is to attach to this screen from a
>> new shell in RemotePC, or a new screen launched from MyPC, such that
>> the deattached screen now becomes attached AND the new shell or screen
>> disappears, with the reattached screen taking its place.
>>
>> Reattaching is easy - there are several screen options that
>> accomplish that. It's getting rid of the new, supporting process
>> (shell or screen) that I just can't pull off. Is this doable in a
>> simple way?
>
> I do something similar to this. Instead of logging in and running screen, I
> log
> in with bash as usual, and then at some point in my .bash_profile I run
>
> exec screen -RD ...
Here's mine. HTH, HAND. twb-agents is basically simplified clone of
Gentoo's keychain.
## The naive "chsh -s /usr/bin/screen" breaks scp (and other things).
## Have sh start screen automatically "when appropriate". That is,
## 1) not in a screen window (STY);
## 2) stdin is a tty;
## 3) screen is installed; and
## 4) terminal is capable of displaying screen.
## Replace "$STY" with "$STY$SSH_CLIENT$SSH_ORIGINAL_COMMAND" to avoid
## nesting screens when sshing (untested).
test -z "$STY" -a -t 0 &&
{ which screen && tput clear && tput cup && ! tput hc && ! tput os
} &>/dev/null && # ignore boring, expected error messages
{
## Set the window title to the host name.
## Note that using echo -e \e for ^[ is not portable.
case "$TERM" in
screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
esac
## If new session, start agents.
screen -ls | grep -qi 'No Sockets found' &&
eval "$(twb-agents)"
## Start screen.
exec screen -DRR
}
## If execution reaches this point, screen isn't the login shell. In
## that case, if this is a bash shell, it's a good idea to do the
## bashisms in .bashrc.
test -n "$BASH" &&
test -f ~/.bashrc &&
. ~/.bashrc
> This replaces the original bash login shell with the reattached screen
> process.
> Detaching from the screen then immediately logs me out.
>
> Andrew.