#!/bin/bash # # SSH tunnel manager (bogdan.vasile.harjoc@fokus.fraunhofer.de) # # This creates and monitors tunnel definitions from all the # *.tun.sh files from the current dir. Screen and wget are required. function log { echo `date '+%F %T'` $*; } function tunnel { fname=$1 . $fname TUNNELS=`echo $TUNNELS | sed -e 's/#[^#]*#//g'` while true; do while true; do log "$fname: testing $TESTURL" wget --timeout=5 -q -O /dev/null $AUTH "$TESTURL" || break sleep 60 done log "$fname: stopping session" for p in `ps aux | egrep "SCREEN.*$fname" | grep -v grep | gawk '{print $2}'` do echo $p; kill $p done sleep 2 log "$fname: starting session" screen -dmS $fname ssh $CONN $TUNNELS sleep 20 done } cd `dirname $0` JOBLIST="" for f in *.tun.sh; do tunnel $f & JOBLIST="$JOBLIST $!" sleep 1 done trap "kill $JOBLIST" INT TERM EXIT wait