Viitor_openvpn/usr/sbin/tunneltest

35 lines
854 B
Plaintext
Raw Normal View History

#!/bin/bash
if [ $1 ]; then
DEVICE=$1
else
DEVICE=tun0
fi
TUN_IP=`grep ifconfig /etc/sysconfig/net/openvpn/$DEVICE.config | awk '{ print $3; };' `
if [ -f /var/run/tunneltest.pid ]; then
ps -ef | grep `cat /var/run/tunneltest.pid` || rm /var/run/tunneltest.pid
fi
if [ ! -f /var/run/tunneltest.pid ]; then
ping -c 1 -i 1 -w 1 $TUN_IP >/dev/null 2>/dev/null
if [ $? != 0 ]; then
PID=`ps -ef | grep tun1 | grep -v grep | awk '{ print $2; }'`
if [ $PID ]; then
kill -1 $PID
fi
sleep 5s
ping -c 1 -i 1 -w 1 $TUN_IP >/dev/null 2>/dev/null
if [ $? != 0 ]; then
PID=`ps -ef | grep tun1 | grep -v grep | awk '{ print $2; }'`
if [ $PID ]; then
kill -9 $PID
fi
sleep 5s
/usr/sbin/openvpn --config /etc/sysconfig/net/openvpn/$DEVICE.config >/dev/null 2>/dev/null &
fi
fi
fi