Eric S. Johansson <e...@harvee.org> 2010-04-19 16:52:
<snip/>
> A better solution may be dtach. I like it better than screen because I 
> use Emacs and I don't care about multiple screens a single terminal 
> session. The reason I don't use it is because I can't invoke it with the 
> logic "use the first unattached session or create a new session."  I want 
> this capability because it would let me stick the head end invocation 
> inside of a login script and solve 90% of my reconnection problems very 
> very simply.

Just to contest the point, that's easily done with screen too.  I source
the attached file from my ~/.bashrc.  It includes some special cases for
local vs. remote vs. cssh sessions, but the idea should be clear enough.

Brian
#!/bin/bash
# ~/.bashrc.d/screen
# 2009-12-21
# bpkroth
#
# Auto launch screen on SSH connections
# Sometimes a pain to deal with SSH screen sessions.
# Can be done with C-a a* though.
# Also a good idea to always use a hardstatus or caption line in .screenrc

if [ $EUID != 0 ] && [[ $TERM != screen* ]] && bin_in_path screen; then
        if [ -n "$LC_CSSH" ]; then
                # This special variable was set to denote this
                # connection as a member of a CSSH session.  Use the
                # value of the variable to select or create a screen
                # session with that name.
                if screen -list | grep "[0-9]\+\.$LC_CSSH[ ]*" > /dev/null; then
                        screen -x $LC_CSSH
                else
                        screen -S $LC_CSSH
                fi
        elif [ -n "$SSH_TTY" ]; then
                # This is a remote session.
                # Connect to the singular screen instance if it is
                # available, else list if there are multiple, else
                # start a new one.
                N=`screen -list | grep -c '[0-9].*tached'`
                if [ $N == 1 ]; then
                        screen -x
                elif [ $N == 0 ]; then
                        #exec screen # no, i want to be able to detach
                        screen
                else
                        echo
                        screen -list
                fi
        #else # local connection, don't open a screen session
        #       #exec screen
        #       screen
        fi
fi

Attachment: signature.asc
Description: Digital signature

_______________________________________________
screen-users mailing list
screen-users@gnu.org
http://lists.gnu.org/mailman/listinfo/screen-users

Reply via email to