I have created a script to check of the DNS is running of a pi-hole service. I run pi-hole in a container on the internet but if that one is offline I would like to switch back to the ISP dns. What I came up with it this:
Code: Select all
:local PIHOLEHOST "pihole.example.com"
:local PIHOLEHOSTIP [:resolve $PIHOLEHOST]
:log info "PI-Hole script started... ($PIHOLEHOSTIP)"
:if ([/ping $PIHOLEHOSTIP interval=1 count=1] = 1) do={
:log info "PI-Hole host is UP! (ping)"
:if ([:resolve $PIHOLEHOST server $PIHOLEHOSTIP]) do={
:log info "PI-Hole DNS is UP! (DNS)"
#/ip dns set servers="$PIHOLEHOSTIP"
#/ip dhcp-client set use-peer-dns=no numbers=0
} else {
:log error "PI-Hole DNS is DOWN! (DNS)"
#/ip dns set servers=""
#/ip dhcp-client set use-peer-dns=yes numbers=0
}
} else {
:log error "PI-Hole host DOWN! (ping)"
#/ip dns set servers=""
#/ip dhcp-client set use-peer-dns=yes numbers=0
}
If I run the resolve command from a ssh session I get this message: failure: dns server failure. So it looks like the if statement does not know how to handle it? Or the scripts get terminated?
So what is the best solution to check if the DNS service on the pi-hole container is running?