55 lines
1.6 KiB
Bash
55 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Standard bash script, requires bash install on OpenWrt
|
|
# and monit to be installed and configured
|
|
|
|
# We assume a few things when this is called, first
|
|
# that the VPN DNS (Expressvpn) is failing second
|
|
# that a restart of openvpn will fix it
|
|
|
|
# Note the location of OpenVPN startup script assuming
|
|
# its already setup and there
|
|
|
|
# Note location of startup script is /etc/init.d/openvpn
|
|
# We assume the OpenVPN file used to configure this connection
|
|
# also has script security set to 2 so we can use the up
|
|
# and down scripts to force the DNS to swap.
|
|
|
|
# Make sure your wan port isn't setup for DHCP as some DHCP
|
|
# setups can cause the DNS to reset from time to time
|
|
# Your ISP's DHCP may not be a problem though as I only
|
|
# encountered this when I had another router upstream
|
|
|
|
# Step one we reset OpenVPN
|
|
# /etc/init.d/openvpn restart
|
|
|
|
# step two we ping a site and see if it resolves
|
|
|
|
# begin hackery
|
|
|
|
# Note: The line below does two things first tries to ping
|
|
# a domain. Second, causes grep to exit with status code
|
|
# 0 if the word "bad" is present otherwise exit 1
|
|
|
|
ping -c 4 expressvpn.com |& grep -q bad
|
|
|
|
# note bash supports |& for piping stderr as to where
|
|
# the default shell doesn't
|
|
|
|
result=${PIPESTATUS[1]}
|
|
# echo "result $result"
|
|
|
|
# ${PIPESTATUS[1]} reffers to the exit code of one of the
|
|
# piped commands in this case the grep
|
|
|
|
if [ $result -eq 1 ]; then
|
|
# If it is ok log it and move on
|
|
logger VPN DNS OK `date`
|
|
fi
|
|
|
|
if [ $result -eq 0 ]; then
|
|
# If we have issue kick a message to syslog and restart
|
|
# Ends up in root.log for remote syslog server
|
|
logger Restarting OpenVPN `date`
|
|
/etc/init.d/openvpn restart # best option to let openvpn handle it
|
|
fi
|