
screen-ssh (scsh)
Mark Allman (mallman@icir.org)

I ssh into a bunch of remote machines from my laptop.  I'd like to
keep these connections up and running, but my laptop wanders to all
sorts of networks and so it just isn't possible.  Ah, but it is said
Robin Sommer, a colleague of mine.  The idea is that if you run
screen on the remote machine then you can just re-ssh in and connect
up.  Well, I am not very good at remembering to start screen
manually (having only been able to muster the energy to use it
occasionally to monitor something over the years).  Robin gave me a
nice enough little script to make it all automatic---just use the
script instead of "ssh" and when the underlying ssh connection fails
it just starts a new instance of ssh and connects up with the old
instance of screen.  Nice idea.  However, its uglier than a loop
around "ssh machine <connect to screen>" if you depend on ssh-agent
propagation and X forwarding.  So, I ended up re-writing what Robin
sent me and this is that script.  So, the ideas are his, but the
bugs are mine and so use at your own risk.  I have been using this
for quite some time with no problems.  It has aided my life
tremendously. 

To use it you have to install two things ...

(1) Drop the 'scsh' script someplace in your PATH where your scripts
    live.

(2) Drop the little bit of needed bash gunk in one of your startup
    files.  (This is used to give the script a way to force the
    shell running inside screen to update a few things to make X11
    and ssh-agent forwarding work.)

Dependencies:

(1) Bash.  One of the bits of goop is bash specific.  It could
    probably be crafted for something else and if someone does it,
    please do send over the code.

(2) Procmail's 'lockfile' tool.  

Usage:

(1) Just "scsh machine" starts the process.  That starts an ssh
    connection to the machine and runs screen on the machine.  When
    the ssh connection fails it is re-started and re-connected to
    the same screen session.  (You can start more than one of these
    to a single machine.)  If you cleanly exit from the remote shell
    (and hence screen) the loop will stop.

(2) You can use "scsh pause" to stop all instances of the scsh
    script from attempting to re-connect to the remote host.  Think
    of this as "airplane mode".  I.e., you know you're not going to
    have network connectivity for a while.

(3) Similarly, "scsh unpause" allows a set of paused scsh instances
    to again try to connect to the remote hosts.

Notes:

  - The script sets up connection sharing unless it is already
    running.
