This is a really short article describing the simplest network monitor ever. At least I think so 😉
So, I was playing with network bridges and I did something wrong, on production of course. After – as we say in Argentina – sweat like a false witness* I was able to recover the connection. This recovery by the way, included the server reboot, and several downtime minutes (and death threats and stuff).
So, before I started to play again with bridges, I wrote the following script to help me to auto recover the network:
#!/bin/bash if ping -c 1 8.8.8.8 then echo "this is fine" sleep 1 exec $0 else systemctl restart networking exec $0 fi
What this script does? sends just 1 ping to the google DNS, if receive an answer wait one second and it start over. If it didn’t receive answer, or there are some error, then restart the network service and start over.
If you didn’t read my first bash scripting article, the variable $0 it’s the script name, but I didn’t run with ./$0 because I think that way I could create a kind of fork bomb. I’m not sure though, if you try that other way at home or work, don’t blame me!