Changeset 8573 for 2.0


Ignore:
Timestamp:
Oct 16, 2010, 7:22:34 PM (14 years ago)
Author:
rick
Message:
  • PWD variable used before declared.
  • sleep on FreeBSD is non interruptable, meaning signals get processed after completion. Which is kind of a pain when you try to stop/kill a script. Made the interval to wait a bit smaller.
  • More logging to aid in better debugging
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2.0/nanobsd/nanobsd/files/usr/local/sshtun/sshtun.sh

    r8572 r8573  
    2222# Revamp to secure and reuse in multiple setups Rick van der Zwet - Oct 2010
    2323
     24PWD=`dirname $0`
     25
    2426# User variables
    2527SSH_HOST=${SSH_HOST:-sshtun.wirelessleiden.nl}
     
    3739
    3840# Internal helpers, storage and shortcuts
    39 PWD=`dirname $0`
    4041SSH_PID=""
    4142
    4243# On (forced) exit, close tunnel and make sure to cleanup the leftovers.
    4344trap_exit() {
     45   SIGNAL=$1
     46   log "Received signal '$SIGNAL'"
    4447   if [ -n "$SSH_PID" ]; then
    4548     kill $SSH_PID
    4649   fi
    4750   rm -f $PIDFILE
     51   exit $SIGNAL
    4852}
    4953
    5054# Don't leave the ssh client process behind and exit with proper exit code
    5155for SIGNAL in 1 2 15; do
    52   trap "trap_exit; exit $SIGNAL" $SIGNAL
     56  trap "trap_exit $SIGNAL" $SIGNAL
    5357done
    5458
     
    7276do
    7377  # Connect to remote site
    74   ssh ${SSH_FLAGS} -i ${SSH_KEY} ${SSH_USER}@${SSH_HOST} -o ServerAliveInterval=5 \
     78  COMMAND="ssh ${SSH_FLAGS} -i ${SSH_KEY} ${SSH_USER}@${SSH_HOST} -o ServerAliveInterval=5 \
    7579    -o ExitOnForwardFailure=yes -o BatchMode=yes  -o StrictHostKeyChecking=no \
    76     -n -N  1>&2 2>> $LOGFILE &
     80    -n -N"
     81  log "[INFO] Connect using $COMMAND"
     82  $COMMAND 1>&2 2>> $LOGFILE &
    7783
    7884  # Save the sshtun PID
     
    8894
    8995  log "[INFO] Sleeping $RECONNECT_TIMEOUT seconds before reconnect"
    90   sleep $RECONNECT_TIMEOUT
     96  SECONDS=$RECONNECT_TIMEOUT
     97  # Nasty hack to avoid shell from ignoring signals while sleeping a long time
     98  while [ $SECONDS -ge 0 ]; do
     99    sleep 5
     100    SECONDS=`expr $SECONDS - 5`
     101  done
     102
    91103done
    92104
Note: See TracChangeset for help on using the changeset viewer.