title: How to programmatically check for connection?
body: <p>In Linux (Ubuntu), I want to programmatically check if there is Internet connection (or if eth0 is connected).</p>
  
  <p>I'm doing this because I am writing a program that requires network connection on a system that is highly prone to lose connection.</p>
  
  <p>So I was thinking maybe a script that I can run periodically to check.</p>
  
  <p>Can you give me good suggestions?</p>