I wrote a watchdog script that checks whether the VPN server on my machine (which is reachable over the internet) is working properly. There have been random issues after long runs that required a reboot.
In a loop, the target host is pinged. After 20 unsuccessful pings, the machine reboots.
Unfortunately, the host used for the ping resolves to an IP that is bound to interface tap0
. RTTs of below a millisecond indicate that no packet has been sent over the internet, so the route I monitor is bridged on the local machine. The machine is connected to the internet via eth0
and can be pinged from any computer. But when using ping -I eth0 <host>
, all I get are timeouts.
traceroute
shows the correct route when using -i eth0
but leaving out the interface results in an instant output with one line, pointing directly to my machine (as the host name resolves to the IP address of tap0
).
Below is my script (okay, this might not really help, but for those of you who are interested, have a look at it):
#!/bin/bash
unsuccessful=0
while [ $unsuccessful -lt 20 ]; do
echo -n " ->"
ping -c 1 -W 2 <addr of vpn server> > /dev/null
if [ $? -ne 0 ]; then
((unsuccessful++))
echo "Unsuccessful: $unsuccessful"
else
unsuccessful=0
echo -n "<- "
fi
sleep 10
done
echo "Bye"
reboot