Get notified when a website comes back online

B3ta.com has been offline all evening. This is not such bad news, as there are other things I should really be doing right now.

It would be nice, however, if my computer could let me know when the site comes back to life. I wrote a quick bash script to do this for me, so I thought I’d share it. This script tries to download a web page every five minutes, and when it succeeds, it will tell  you the website has come back online and open the page in your browser.

If you’re not using OS X, you might have to make a few changes to get the text-to-speech announcement working and to open the web page in your browser. I’m sure it won’t be too difficult.

#!/bin/bash
# 
# Poll a website until it comes back online, then open it in
# the default web browser.
# 
# Edit the following two lines:
URL="http://www.b3ta.com/board"
TITLE="The b3ta board"
# 
until [ "`curl -s --connect-timeout 5 --head $URL 2>/dev/null`" ]; do
  sleep 300
done
say "$TITLE is back online"
open $URL

Before anyone says anything — yes, I know it could be improved. I should at least check for a 200 OK response code. But this will do for the time being; the b3ta server isn’t even responding to pings at the moment.

Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Please enter the missing number: *