on Wed, Apr 17, 2002, Dave Carrigan (dave@rudedog.org) wrote:
> Rory Campbell-Lange <rory@campbell-lange.net> writes:
>
> > Is it possible to log back into a machine over ssh and 'attach' to a
> > running process so that one can see the output of, say, a kernel
> > compile?
>
> If you find that you often need to reattach to processes between ssh
> sessions, look into running screen. It lets you detach and reattach to
> any number of long-lived processes.
Example:
$ ssh remotehost
Enter passphrase for RSA key '/home/karsten/.ssh/identity':
[remotehost]$ screen
# screen splash screen
[remotehost]$ top
<ctrl><d>
[detached]
[remotehost]$ exit
Connection to remotehost closed.
$ ssh remotehost
Enter passphrase for RSA key '/home/karsten/.ssh/identity':
[remotehost]$ screen -r
# Display now continues to show 'top' output.
...Useful key combos. C-a == <ctrl>-a, so C-a c == <ctrl>-A (single
keystroke) plus 'c'. 'Window' refers to one of the multiplexed shells
under screen.
C-a c: 'create' new window. You can spawn a large number, I'm
up to 30 in a test session.
C-a n: 'next' window.
C-a n: 'prior' window.
C-a a: 'alternate' window -- switch to most recent prior.
C-a <number>: Switch to window number <number>.
C-a d: 'detach' -- disconnect from screen session. Screen (and
any processes in it) continue to run.
C-a k: 'kill' current screen window.
C-a-a: Send a 'control-a' to the current screen. Useful if you
use emacs bash shell editing mode.
C-a ?: 'help' -- with this and other functions.
From the shell:
$ screen -ls # List screen sessions
$ screen -r # Reattach to the detached screen process.
$ screen -r <session> # Reattach to a specified screen process.
$ screen -rd # Reattach, detaching existing session if any.
$ screen -rx # Reattach, preserving existing session if any (shared).
I'm also attaching two scripts I use to run w3m in screen mode within an
rxvt, with a wrapper that I use to invoke w3m generally.
I put the wrapper in /usr/local/bin (which precedes /usr/bin on my
path).
This gives me w3m in an terminal window, invoked via screen, so I can
multiplex my browsing session. Note trix with the SHELL variable.
'screen' sees its shell as w3m, so a new w3m session is spawned for each
new window. w3m resets shell to /bin/bash to allow proper shell escapes
from the browser itself. I use this for most of my quick-and-dirty
browsing needs.
- w3m: w3m wrapper. Invokes w3m on bookmarks file if no args given.
- w3m-term: Invokes w3m within terminal using screen.
Peace.
--
Karsten M. Self <kmself@ix.netcom.com> http://kmself.home.netcom.com/
What Part of "Gestalt" don't you understand?
The best damned coffee on the planet:
Graffeo Coffee, 735 Columbus Ave., San Francisco, California, USA, Earth
http://www.graffeo.com/
#!/bin/bash
# A w3m wrapper to allow no-argument startup.
export SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
realw3m=/usr/bin/w3m # Actually, a wrapper itself <g>
arg="" # initialize
# Only subs if no args given and env doesn't say otherwise
if [ $# -eq 0 -a \( -z "$HTTP_HOME" -a -z "$WWW_HOME" \) ]; then
# DEBUG: echo "No args, hunting the wumpus"
for arg in \
$HOME/.w3m/bookmark.html \
$HOME/.netscape/bookmarks.html \
$HOME/.w3m/bookmark.html \
$HOME/.w3m/bookmark.html \
$HOME/.netscape/bookmarks.html \
$HOME/.galeon/bookmarks.xml
do
if [ -f $arg ]; then
# DEBUG: echo "arg set to: $arg"
break
fi
done;
else
: # DEBUG: echo "Args: $#"
fi
$realw3m $arg "$@"
#!/bin/sh PATH=/usr/bin:/bin:/usr/X11R6/bin exec rxvt -e w3m $@ &
Attachment:
pgpexeFgUyixE.pgp
Description: PGP signature