1

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 1

0

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 &>> $LOGFILE

Make the script executable and put it in crontab to run every minute

* * * * * /var/my/script/scriptname
1
  • I wonder why this answer has been downvoted?
    – not2savvy
    Feb 8, 2019 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.