I've had some issue finding a good starting point on building an auto re-connect script for a vpnc connection. I have a VPN configured for Cisco IPsec that drops fairly frequently and I need to have it auto re-connect. I'm running a headless Ubuntu 14.04 server and have very basic knowledge of bash scripting.
Any help finding an answer would be much appreciated. If there is any other info you might need to help out I'm happy to provide.
Cheers!
1 Answer
I know this is an old question, but since nobody answer :)
This is the script I use, it will try to connect to a host 3 times, then reconnect the vpn.
#!/bin/bash
TESTIP=<ip to test>
TESTPORT=<port to test>
VPNCONNECT=/usr/sbin/vpnc-connect
LOGFILE=/var/log/vpncreconnect.log
if nc -w2 -z $TESTIP $TESTPORT ; then exit
fi
if nc -w3 -z $TESTIP $TESTPORT ; then exit
fi
if nc -w4 -z $TESTIP $TESTPORT ; then exit
fi
echo "`date`: unable to connect to target, restarting VPN..." >> $LOGFILE
$VPNCONNECT &>> $LOGFILEMake the script executable and put it in crontab to run every minute
* * * * * /var/my/script/scriptname 1