Changeset 8573 for 2.0/nanobsd
- Timestamp:
- Oct 16, 2010, 7:22:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2.0/nanobsd/nanobsd/files/usr/local/sshtun/sshtun.sh
r8572 r8573 22 22 # Revamp to secure and reuse in multiple setups Rick van der Zwet - Oct 2010 23 23 24 PWD=`dirname $0` 25 24 26 # User variables 25 27 SSH_HOST=${SSH_HOST:-sshtun.wirelessleiden.nl} … … 37 39 38 40 # Internal helpers, storage and shortcuts 39 PWD=`dirname $0`40 41 SSH_PID="" 41 42 42 43 # On (forced) exit, close tunnel and make sure to cleanup the leftovers. 43 44 trap_exit() { 45 SIGNAL=$1 46 log "Received signal '$SIGNAL'" 44 47 if [ -n "$SSH_PID" ]; then 45 48 kill $SSH_PID 46 49 fi 47 50 rm -f $PIDFILE 51 exit $SIGNAL 48 52 } 49 53 50 54 # Don't leave the ssh client process behind and exit with proper exit code 51 55 for SIGNAL in 1 2 15; do 52 trap "trap_exit ; exit$SIGNAL" $SIGNAL56 trap "trap_exit $SIGNAL" $SIGNAL 53 57 done 54 58 … … 72 76 do 73 77 # 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 \ 75 79 -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 & 77 83 78 84 # Save the sshtun PID … … 88 94 89 95 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 91 103 done 92 104
Note:
See TracChangeset
for help on using the changeset viewer.