Gonzalo Rivero
Gonzalo Rivero
I am Gonzalo, I live in Salta, a city located in the NW of Argentina. I play the guitar and a little harmonica. I also like to bike.

Simple(st) network monitor

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:

if ping -c 1
	echo "this is fine"
	sleep 1
	exec $0
	systemctl restart networking
	exec $0

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!


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook