Skip to content

Instantly share code, notes, and snippets.

@cybic
Last active January 24, 2020 11:55

Revisions

  1. cybic revised this gist Jan 24, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion remux-hop
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,9 @@
    # AutoSSH to host and create or connect to tmux session
    # Multi-hop version. Separate hops with `%`. Assign port with `:`
    #
    # remux-hop alice.example.com%[email protected]:2222 sysop
    # $ remux-hop server.example.com sysop
    # $ remux-hop alice.example.com%bob.example.com sysop
    # $ remux-hop alice.example.com%[email protected]:2222 sysop
    #
    # Author: Oystein Steimler <[email protected]>

  2. cybic revised this gist Jan 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion remux-hop
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # AutoSSH to host and create or connect to tmux session
    # Multi-hop version. Separate hops with `%`. Assign port with `:`
    #
    # remux-hop alice.example.com%[email protected]:2222
    # remux-hop alice.example.com%[email protected]:2222 sysop
    #
    # Author: Oystein Steimler <[email protected]>

  3. cybic revised this gist Jan 24, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions remux-hop
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    #!/bin/bash
    #
    # AutoSSH to host and create or connect to tmux session
    # Multi-hop version. Separate hops with `#`. Assign port with `:`
    # Multi-hop version. Separate hops with `%`. Assign port with `:`
    #
    # remux-hop alice.example.com#[email protected]:2222
    # remux-hop alice.example.com%[email protected]:2222
    #
    # Author: Oystein Steimler <[email protected]>

  4. cybic revised this gist Nov 22, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions remux-hop
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@

    HLIST=$1;

    IFS='#' read -a HOPS <<< "$HLIST"
    IFS='%' read -a HOPS <<< "$HLIST"

    AUTOSSHPRM="-M0 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o BatchMode=yes"
    SSHPRM="-A -t"
    @@ -41,4 +41,4 @@ then
    else
    echo SSH;
    ssh $SSHPRM ${HOPS[0]} $CMD;
    fi;
    fi;
  5. cybic revised this gist Mar 10, 2016. 1 changed file with 21 additions and 5 deletions.
    26 changes: 21 additions & 5 deletions remux-hop
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,44 @@
    #!/bin/bash
    #
    # AutoSSH to host and create or connect to tmux session
    # Multi-hop version. Separate hops with :
    # Multi-hop version. Separate hops with `#`. Assign port with `:`
    #
    # remux-hop alice.example.com#[email protected]:2222
    #
    # Author: Oystein Steimler <[email protected]>

    HLIST=$1;

    IFS=':' read -a HOPS <<< "$HLIST"
    IFS='#' read -a HOPS <<< "$HLIST"

    AUTOSSHPRM="-M0 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o BatchMode=yes"
    SSHPRM="-A -t"
    CMD="if tmux ls | grep ^$2; then tmux att -t $2; else tmux new -s $2;fi";
    for ((i=${#HOPS[@]}-1; i>=1; i--))
    do
    PCMD=$(printf %q "$CMD");
    CMD="if [ \`which autossh\` ] ; then echo AutoSSH; autossh $AUTOSSHPRM -t ${HOPS[$i]} $PCMD; else echo SSH; ssh -t ${HOPS[$i]} $PCMD; fi ";

    ## Separate host from port
    IFS=':' read -a HOSTPARTS <<< "${HOPS[$i]}"
    HOP=${HOSTPARTS[0]}
    if [ -n "${HOSTPARTS[1]}" ]
    then
    echo "Setting port $PORT"
    PORT="-p ${HOSTPARTS[1]} ";
    fi

    ## Push a hop to the stack.
    CMD="if [ \`which autossh\` ] ; then echo 'AutoSSH $HOP $PORT'; autossh $AUTOSSHPRM $SSHPRM $PORT $HOP $PCMD; else echo 'SSH $HOP $PORT'; ssh $SSHPRM $PORT $HOP $PCMD; fi ";
    done

    #echo $CMD;
    #exit;

    if [ `which autossh` ];
    then
    echo AutoSSH;
    autossh $AUTOSSHPRM -t ${HOPS[$i]} $CMD;
    autossh $AUTOSSHPRM $SSHPRM ${HOPS[$i]} $CMD;
    else
    echo SSH;
    ssh -t ${HOPS[0]} $CMD;
    ssh $SSHPRM ${HOPS[0]} $CMD;
    fi;
  6. cybic revised this gist Mar 10, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion remux-hop
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,6 @@ do
    done
    #echo $CMD;

    #ssh -t ${HOPS[0]} $CMD
    if [ `which autossh` ];
    then
    echo AutoSSH;
  7. cybic created this gist Mar 10, 2015.
    29 changes: 29 additions & 0 deletions remux-hop
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash
    #
    # AutoSSH to host and create or connect to tmux session
    # Multi-hop version. Separate hops with :
    #
    # Author: Oystein Steimler <[email protected]>

    HLIST=$1;

    IFS=':' read -a HOPS <<< "$HLIST"

    AUTOSSHPRM="-M0 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o BatchMode=yes"
    CMD="if tmux ls | grep ^$2; then tmux att -t $2; else tmux new -s $2;fi";
    for ((i=${#HOPS[@]}-1; i>=1; i--))
    do
    PCMD=$(printf %q "$CMD");
    CMD="if [ \`which autossh\` ] ; then echo AutoSSH; autossh $AUTOSSHPRM -t ${HOPS[$i]} $PCMD; else echo SSH; ssh -t ${HOPS[$i]} $PCMD; fi ";
    done
    #echo $CMD;

    #ssh -t ${HOPS[0]} $CMD
    if [ `which autossh` ];
    then
    echo AutoSSH;
    autossh $AUTOSSHPRM -t ${HOPS[$i]} $CMD;
    else
    echo SSH;
    ssh -t ${HOPS[0]} $CMD;
    fi;