First Post and SMS Ping Script

Thanks for visiting!  The main purpose of this blog (right now) is as an archive for useful technical bits and pieces I’ve come across and don’t want to forget.  Hopefully, you might find some of these useful, too.   This is my first post and I’d like to start by sharing a handy little script-foo I learned.

Over Christmas, the Compsoc admin team reinstalled our backup server.  We created a fairly large (~3.6T RAID5) /home partition which took forever to build when the server booted for the first time.  Rather than keep checking into the server room I figured “Wouldn’t it be handy if I could just get a text when the server comes up?”.

I decided to use a great tool called o2sms by Mackers that’s installed on Compsoc’s webserver.  It allows you to send text messages via the command line.  The following script intermittently pings the backup and sends an SMS to the specified number when a ping returns successfully:

$while ! ping -W 1 -c 1 IPAddress 2>&1 >/dev/null; do true; done && echo “Scorpio is UP” | meteorsms mynumber

Its a simple little diddy ain’t it?  Run it in a screen and you can detach, logout and go about your day.  Drop the ! and it will send an SMS if  a ping fails (maybe the servers down).  You could also replace ping with another event, such as a certain user logging in (users | grep andrewjregan) or if you recieve a new mail.

Tags: , , , , ,

2 Responses to “First Post and SMS Ping Script”

  1. Duffy 10 December, 2010 at 23:24 #

    I was doing something like this for awhile however I found it expensive when my o2 texts ran out, as well as this I found the o2 website was down or changing a lot. It made the method very unstable.

    At this moment in time I’m using one based around twitter and SMTP.
    I noticed twitter supply free sms alerts to o2 so I created two accounts a sms account and a feed account.
    I set it up so duffy(at)sms.tuts4tech.net goes to procmail which then tweets the email subject on the feed account.
    The sms account is following the feed account and has SMS alerts enabled so when the feed account tweets anything I get an SMS :)

    I run a smokeping server and enabled SMTP alerts which resulted in me being alerted if a server went down or if packet loss was experienced to it.

  2. Andy 23 December, 2010 at 10:02 #

    Ha! That’s really clever.

Leave a Reply