title: Run script after network is connected
body: <p>Placing files in <code>/etc/network/if-up.d/</code> you can invoke a script whenever the interface is brought up. But that doesn't mean internet connectivity has been established. This happens to me quite frequently. For instance, the code below</p>
  
  <pre><code>#!/bin/sh
  
  # Don't bother to do anything for lo.
  if [ "$IFACE" = lo ]; then
      exit 0
  fi
  
  # Only run from ifup.
  if [ "$MODE" != start ]; then
      exit 0
  fi
  
  # we only care about inet and inet6.
  case $ADDRFAM in
      inet|inet6|NetworkManager)
          ;;  
      *)  
          exit 0
          ;;  
  esac
  
  
  /path/to/my/script
  
  exit 0
  </code></pre>
  
  <p>Calls the script as soon as interface is brought up. But most often, I still do not have network connectivity, so my script fails because it tries to connect to the web.</p>
  
  <p>What am I doing wrong?</p>