The Internet Is Back up - a Reminder Script

Reading time ~1 minute

Want to learn more about Scripts? Sign up for my mailing list!

ARGGG! The internet went out. What to do while I wait? I know! Write a bash script to let me know when the internet is back up!

Line by line starting after the ‘Begin ping’:

  1. Starts a for loop with 1000 loops.
  2. Tries to ping google (-q)uietly for a response and only sends a (-c)ount of 1 packet as a test
  3. It then uses the built in OS X voice ‘Zarvox’ to inform me I need to get back to work
  4. After that it echos to the terminal that the internet has come back
  5. And pipes the result of an echo command to the mail command which sends a text message to my phone with t-mobiles mail-to-text address. (Most carriers have some version of this).
#!/usr/bin/env bash
echo 'Begin ping'
for i in {1..1000}
do
       if ping -q -c 1 www.google.com
       then
       say -v Zarvox 'The internet has returned. Back to work mortal.'
       echo "The internet has returned"
       echo "The Internet is Back" | mail -s "Internet Is Back" 5555555555@tmomail.net
       exit
       fi
       sleep 5
done

I hope you never have to use it!

Have questions? Feel free to leave them below!