I got tired a long time ago of losing what I was currently working on in SSH sessions when they were lost due to disconnects from network connectivity issues. To combat this I have been using screen when running sessions that I can absolutely not lose, but the problem still persists in other sessions or when I forgot to run it. The easy solution to this was to add screen to one of my bash init scripts (~/.bashrc [or ~/.bash_profile]) as follows:
alias autoscreen="screen -x -RR && exit"This automatically makes the screen command run on bash user initialization, always connecting to the same session.
if [[ "$TERM" == cygwin* || "$TERM" == xterm* ]]; then autoscreen; fi
if [ $TERM == "xterm" ]; then screen -R pts-0.`hostname` && exit; fi
Edit on 2010-12-30 @ 3:50am: I changed != "screen" to == "xterm" because otherwise scp and some other non-term programs were failing. You may have to use something other than “xterm” for your systems.
Edit on 2010-1-24 @ 2:00pm: I added the exit; so the terminal automatically exits when the screen session closes.