From Mammoth Hog, 3 Weeks ago, written in Bash.
This paste is a reply to syno-vpn-keepalive.sh from hava - view diff
Embed
  1. # syno-vpn-keepalive.sh
  2. # ---
  3. # Script to keep VPN alive on Synology DSM.
  4. # Checks if IP is pingable and if not:
  5. #  disconnect VPN, reconnect VPN & add routes
  6. # ---
  7. # Modify vars:
  8. # - CHECKIP: IP to check to be pingable before reconnecting VPN
  9. # - NAME (Synology VPN name),
  10. # - ID (Synology VPN ID), SSH to NAS & run this to find ID
  11. #    sudo grep conf_id /usr/syno/etc/synovpnclient/vpnc_last_connect
  12. # - PROTO (pptp|l2tp|openvpn),
  13. # - DEV
  14. #     VPN network device -
  15. #     check using ifconfig while VPN connected, *ppp200* for example)
  16. # - ROUTE1,
  17. #     Route to add after connecting VPN (network/prefix)
  18. # - ROUTE2
  19. #     Another route to add efter connecting VPN (network/prefix)
  20. #
  21. # To install, go to **Control Panel > Task Scheduler**
  22. #
  23. #   Hit **Create > Scheduled Task > User-defined Script**
  24. #
  25. #   ## General
  26. #   - Task: **VPN keepalive**
  27. #   - User: **root**
  28. #  
  29. #   ## Schedule
  30. #   - Run on the following days: **Daily**
  31. #   - First run: **00:00**,
  32. #   - Frequency: **Every 5 min(s)**,
  33. #   - last run time: **23:55**
  34. #  
  35. #   ## Task settings
  36. #   - Run command - User defined script:
  37. #     *paste this entire script's content*
  38. # ---
  39.  
  40. CHECKIP='10.1.10.48'
  41. NAME='Connexeon'
  42. ID='p1489396766'
  43. PROTO='pptp'
  44. DEV='ppp200'
  45. ROUTE1='10.0.0.0/12'
  46. ROUTE2='10.111.0.0/24'
  47.  
  48. if ping -c 1 $CHECKIP &> /dev/null
  49. then
  50.   echo "VPN is running ($CHECKIP pingable)"
  51.   synovpnc get_conn
  52.   route
  53. else
  54.   echo "Reconnecting VPN ($CHECKIP unresponsive)"
  55.  
  56.   echo "Killing VPN ($NAME)"  
  57.   synovpnc kill_client --name=$NAME
  58.  
  59.   echo "Reconnecting VPN ($NAME - $PROTO)"  
  60.  
  61.   echo conf_id=$ID > /usr/syno/etc/synovpnclient/vpnc_connecting
  62.   echo conf_name=$NAME >> /usr/syno/etc/synovpnclient/vpnc_connecting
  63.   echo proto=$PROTO >> /usr/syno/etc/synovpnclient/vpnc_connecting
  64.   synovpnc reconnect --protocol=$PROTO --name=$NAME
  65.  
  66.   echo "Adding route ($ROUTE1 - $DEV)"  
  67.   route add -net $ROUTE1 dev $DEV
  68.  
  69.   echo "Adding route ($ROUTE2 - $DEV)"  
  70.   route add -net $ROUTE2 dev $DEV
  71. fi
  72. exit 0
  73.  
  74.  

Replies to Re: syno-vpn-keepalive.sh rss

Title Name Language When
Re: Re: syno-vpn-keepalive.sh Commodious Treeshrew bash 3 Weeks ago.
Re: Re: syno-vpn-keepalive.sh Lousy Pudu bash 3 Weeks ago.