Check your Server's Pulse with Twitter

I had a problem – a remote server that I couldn’t check the status of.  It is located a friend’s house and I would occasionally lose contact with it.  Sometimes it would be down (he apparently doesn’t have reliable electricity) and I wouldn’t notice it for a week or two.  This server acts as my remote backup server, so I didn’t want to potentially miss an important backup run.

While others view Twitter as a great social networking, Web 2.0, whatever, I see it as a free update/status server.  Several folks have talked about updating Twitter from the command line:

http://lightlinux.blogspot.com/2009/06/twitter-updates-from-linux-cli.html

http://www.junauza.com/2009/03/follow-me-twitting-from-linux-command.html

I decided to use curl (as described in the blogs above) to setup a heartbeat from my remote server.  Essentially, every half hour, the remote server sends out a tweet with its full hostname and the local time to Twitter.  If I am ever curious about whether the remote server is up, I can check Twitter, and also figure out approximately when it went down, based upon the time of the last update.  I have been using the following bash script:

#!/bin/bash
curl –basic -u  “username:password” -d “status=$(hostname -f) is alive at $(date) local time.” http://www.twitter.com/statuses/update.xml >/dev/null

I have cron setup to run the script every half hour, although you can change the update interval to suit your own needs.  I also created a separate Twitter account strictly for this purpose and made it private.

In the future, I may utilize Twitter’s RSS feature to send me an email if a server misses an update.

This entry was posted in Software and tagged , , , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>