Monitor internet connectivity through the command line

If you have an intermittent internet connection, this is how you can monitor it through the command line, and maybe also generate logs to send to your ISP for troubleshooting. This works on the Mac and maybe for Linux (not tested):

ping | while read pong; do echo "$(date): $pong"; done