3 # usage: I run this script on a timer to correct the dns on wrt for
4 # clients where dns is updated dynamically by openvpn, in the case that
5 # openvpn crashes or the computer running openvpn crashes.
8 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
10 x
="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} # directory of this file
12 while read -r ip
host; do
14 is_connected
="grep -q "^CLIENT_LIST
,$host," /run/openvpn-server/status-server.log"
15 if $is_connected; then continue; fi
16 if ! grep -q "^CLIENT_LIST,$host," /run
/openvpn-server
/status-server.log
; then
17 cd $
(mktemp
-d); dir
=$PWD
18 ssh wrt
tar -C /etc
-c hosts |
tar -x
19 if grep -qFx "$ip $host" hosts
; then continue; fi
20 # openvpn udpates its status file every 60 seconds by default
21 if (( $
(stat
-c%Y hosts
) > EPOCHSECONDS
+ 60 )); then
23 if $is_connected; then continue; fi
25 ssh root@wrt.b8.nz cedit ovpn-
$host <<<"$ip $host" ||
[[ $?
== 1 ]]