VPNC经常假死需要重启的脚本

定义自己需要ping通的VPN内部地址TESTPOINT,定义自己的logfile文件,/etc/vpn/hk.conf看自己配置文件名进行更改。

#!/bin/bash
TESTPOINT="192.168.2.1"
LOGFILE=/etc/vpnc/autovpn.log
 
if ping -c 1 $TESTPOINT &> /dev/null
then
	echo 1
else
	pid=$(pidof vpnc)
	if test -z${pid}then
		echo “$(date +%Y-%m-%d:%T) pid is null” | tee -a $LOGFILE
		echo “$(date +%Y-%m-%d:%T) restarting vpnc” | tee -a $LOGFILE
		/usr/sbin/vpnc /etc/vpnc/hk.conf| tee -a $LOGFILE
	else
		echo “$(date +%Y-%m-%d:%T) vpnc is running but not connected. killing ${pid}| tee -a $LOGFILE
		kill -9 ${pid}
		echo “$(date +%Y-%m-%d:%T) restarting vpnc” | tee -a $LOGFILE
		/usr/sbin/vpnc /etc/vpnc/hk.conf | tee -a $LOGFILE
		echo “$(date +%Y-%m-%d:%T) vpnc running with pid: $(pidof vpnc)| tee -a $LOGFILE6
	fi
 
fi

参考链接:

https://www.mycodingpains.com/lstable-vpnc-connection-ubuntu-2-2/