I am having a few problems with a script I am trying to write which monitors ssh tunnels and brings them back up if they die.
Here is the code
DOWN=`echo "Tunnel Down"`
TUNNEL1=`ps ax | grep "2080:192.168.20.11:80" | grep -v grep | wc -l`
TUNNEL2=`ps ax | grep "2080:192.168.20.12:80" | grep -v grep | wc -l`
TUNNEL3=`ps ax | grep "2080:192.168.20.13:80" | grep -v grep | wc -l`
TUNNEL4=`ps ax | grep "2080:192.168.20.14:80" | grep -v grep | wc -l`
TUNNEL5=`ps ax | grep "20000:192.168.21.10:20000" | grep -v grep | wc -l`
for tunnels in $TUNNEL1 $TUNNEL2 $TUNNEL3 $TUNNEL4 $TUNNEL5
if [ $tunnels -eq 1 ]
echo "$(date) SSH $tunnels up"
echo "$tunnels $DOWN $(date)"
As you will see it isn't very intelligent in the fact you can't tell which tunnel has gone down so there is no way of bringing it back up. I am running out of ideas on how I can approach this so any help would be gratefully received.