u/Embarrassed-Point349

Script to restart OpenVPN connection

This is a script (for a scheduled task in my case) to disconnect and reconnect OpenVPN.

This is mostly pulled together from various other people's stuff online, but none of their scripts worked for me out of the box. Hence this.

If you want the logging to work you'll need to create /volume1/Media/Logs

I'm using:

  • DS220+

  • DSM 7.3.2-86009 Update 3

  • Built-in OpenVPN support

  • IPVanish as my VPN provider

    Force a reconnect for the specific VPN profile

    #VPN Names and Conf IDs: #Brussels17, o1775835752

    DAY0=date -I TIME0=date -u touch /volume1/Media/Logs/vpn-$DAY0.log

    echo "--Task running at:" $TIME0 >>/volume1/Media/Logs/vpn-$DAY0.log /usr/syno/bin/synovpnc get_conn >>/volume1/Media/Logs/vpn-$DAY0.log

    echo "Killing client" >>/volume1/Media/Logs/vpn-$DAY0.log /usr/syno/bin/synovpnc kill_client

    Sleep 10

    echo "Creating vpnc_connecting file" >>/volume1/Media/Logs/vpn-$DAY0.log echo "conf_id=o1775835752" > /usr/syno/etc/synovpnclient/vpnc_connecting echo "conf_name=Brussels17" >> /usr/syno/etc/synovpnclient/vpnc_connecting echo "proto=openvpn" >> /usr/syno/etc/synovpnclient/vpnc_connecting

    echo "Reconnecting" >>/volume1/Media/Logs/vpn-$DAY0.log /usr/syno/bin/synovpnc reconnect --protocol=openvpn --name=Brussels17 --retry=5 --interval=30

    Sleep 5

    TIME0=date -u echo "Connections as at:" $TIME0 >>/volume1/Media/Logs/vpn-$DAY0.log /usr/syno/bin/synovpnc get_conn >>/volume1/Media/Logs/vpn-$DAY0.log

    echo "--Task completed at:" $TIME0 >>/volume1/Media/Logs/vpn-$DAY0.log

reddit.com
u/Embarrassed-Point349 — 15 hours ago