What's new

Is there a command line to automaticly reconnect the VPN on a timer

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Alternatively, there is the stop and start syntax available:

service stop_vpnclient1
service start_vpnclient1

Code:
cru

Cron Utility
add:    cru a <unique id> <"min hour day month week command">
delete: cru d <unique id>
list:   cru l

Code:
cru a VPN_START "0 2 * * * service stop_vpnclient1 #Stop VPN at 2 AM
cru a VPN_STOP "0 13 * * * service start_vpnclient1 #Start VPN at 1 PM
 
for reference, here's the script that I use to check whether the VPN tunnel is up (by pinging google.com). If not, reset it.


#/bin/sh

ping -c 1 -w 3 -I tun11 google.com

if [ $? -eq 0 ]; then
date +"%Y-%m-%d %r - UP" >> /dev/null
else
date +"%Y-%m-%d %r - DOWN" >> /jffs/scripts/check.log
service restart_vpnclient1
fi
 
for reference, here's the script that I use to check whether the VPN tunnel is up (by pinging google.com). If not, reset it.


#/bin/sh

ping -c 1 -w 3 -I tun11 google.com

if [ $? -eq 0 ]; then
date +"%Y-%m-%d %r - UP" >> /dev/null
else
date +"%Y-%m-%d %r - DOWN" >> /jffs/scripts/check.log
service restart_vpnclient1
fi
Do you run that from a cron job or a /jffs/scripts/<some startup script> ?
 
That is what I did.

To help others, here is a detailed setup.
Use the script from @datan above. I placed it in /jffs/scripts as "vpncheck.sh"
Code:
#/bin/sh

ping -c 1 -w 3 -I tun11 google.com

if [ $? -eq 0 ]; then
date +"%Y-%m-%d %r - UP" >> /dev/null
else
date +"%Y-%m-%d %r - DOWN" >> /jffs/scripts/check.log
service restart_vpnclient1
fi

Remember it needs full permissions using chmod 755
Code:
chmod 755 /jffs/scripts/vpncheck.sh

Add this to /jffs/scripts/services-start.
(The "*/5" means it checks every 5 minutes, adjust for your preferences.)
Code:
cru a CheckVPNTunnel "*/5 * * * * /jffs/scripts/vpncheck.sh"

To manually start it without running /jffs/scripts/services-start Use this on the command line
Code:
cru a CheckVPNTunnel "*/5 * * * * /jffs/scripts/vpncheck.sh"

After that it will be set to run after every router reboot.
 
As a followup, today I had the first VPN client failure, but was able to confirm that the script from @datan works!

Code:
Oct 12 10:00:09 RT-AC86U-4608 ovpn-client1[7415]: Initialization Sequence Completed
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: event_wait : Interrupted system call (code=4)
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: vpnrouting.sh tun11 1500 1552 10.200.0.82 10.200.0.81 init
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: Closing TUN/TAP interface
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: /sbin/ifconfig tun11 0.0.0.0
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: updown.sh tun11 1500 1552 10.200.0.82 10.200.0.81 init
Oct 22 09:25:12 RT-AC86U-4608 ovpn-client1[7415]: SIGTERM[hard,] received, process exiting
Oct 22 09:25:13 RT-AC86U-4608 ovpn-client1[21469]: OpenVPN 2.4.9 arm-buildroot-linux-gnueabi [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] built on Apr 25 2020
Oct 22 09:25:13 RT-AC86U-4608 ovpn-client1[21469]: library versions: OpenSSL 1.1.1g  21 Apr 2020, LZO 2.08
Oct 22 09:25:13 RT-AC86U-4608 ovpn-client1[21470]: NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Oct 22 09:25:14 RT-AC86U-4608 ovpn-client1[21470]: TCP/UDP: Preserving recently used remote address: [AF_INET]xxx.58.130.yyy:pppp

( %< snip )

Oct 22 09:25:20 RT-AC86U-4608 ovpn-client1[21470]: TUN/TAP device tun11 opened
Oct 22 09:25:20 RT-AC86U-4608 ovpn-client1[21470]: TUN/TAP TX queue length set to 1000
Oct 22 09:25:20 RT-AC86U-4608 ovpn-client1[21470]: /sbin/ifconfig tun11 10.200.0.14 pointopoint 10.200.0.13 mtu 1500
Oct 22 09:25:20 RT-AC86U-4608 ovpn-client1[21470]: updown.sh tun11 1500 1552 10.200.0.14 10.200.0.13 init
Oct 22 09:25:22 RT-AC86U-4608 ovpn-client1[21470]: Initialization Sequence Completed
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top