VPNreconnect/VPNreconnect.sh

40 lines
1.3 KiB
Bash

#!/bin/sh
# /volume1/homes/admin/script/VPNreconnect.sh
# Quellen:
# https://www.synology-forum.de/showthread.html?95824-Skript-um-VPN-Verbindung-zu-pr%C3%BCfen-und-wiederherstellen&p=779549&viewfull=1#post779549
# weitere Info: https://mickderksen.wordpress.com/2016/06/08/how-to-schedule-a-vpn-connection-on-synology/
# Aufruf:
# sh ./VPNconnect.sh remoteIP
ConfID="" # optional und falls bekannt / bei mehreren VPN-Verbindungen notwendig
########## ab hier nichts mehr ändern ##########
VPNreconnect ()
{
CONNFILE=/usr/syno/etc/synovpnclient/vpnc_connecting
sudo sh -c "echo conf_id=${ConfID} > /usr/syno/etc/synovpnclient/vpnc_connecting"
sudo sh -c "echo conf_name=${ConfID} >> /usr/syno/etc/synovpnclient/vpnc_connecting"
sudo sh -c "echo proto=l2tp >> /usr/syno/etc/synovpnclient/vpnc_connecting"
sudo synovpnc connect --id=${ConfID}
}
if [ -z $ConfID ]; then
ConfID=`get_key_value /usr/syno/etc/synovpnclient/vpnc_last_connect conf_id`
fi
#remote_IP="10.8.0.1" # fest eingestellte IP
# Aufruf mit Prüfung:
remote_IP=$1 # als Parameter übergebene IP
df | grep "${remote_IP}" > /dev/null
if [ $? -eq 0 ]; then
echo "==> OK - Verbindung ist zu ${remote_IP} erfolgreich aufgebaut"
else
echo "==> Verbindung wird zu ${remote_IP} neu hergestellt:"
VPNreconnect
fi