computer science, math, programming and other stuff
a blog by Christopher Swenson

curl + twitter + crontab = Happiness

I've always wanted to know how my servers are doing. I don't have time to check on every single one of them all of the time. In the past, this meant perhaps an automatic email sent to me at some specified time during the day.

But emails are annoying. RSS is definitely the technology that would be nice, but how to implement it?

Twitter is ideal for this purpose. Multiple people (admins?) can check the status of a server as it is updated, and you can lock it down so that only authorized people can view the status.

Updating is easy using the Twitter API through curl. I just wrote the following bash script to update a twitter feed for a specified user:

#!/bin/bash

USER="server"
PASS="password"
URL="http://twitter.com/statuses/update.xml"
STATUS="[`hostname`] `uptime`, `df -h / | grep -o -e '[0-9][0-9]*%'` HD used"

curl --basic --user $USER:$PASS --data status="$STATUS" $URL

This automatically sends updates that look like:

[servname] 11:23:20 up 7 days, 14:43, 1 user, load average: 0.18, 0.36, 0.17, 83% HD used

Then I name it something useful, like /root/twitter.sh, and add a crontab entry:

0 0 * * * /root/twitter.sh >& /dev/null

And I'm set.

Naturally, this was designed to work for Linux, and would probably work on OS X and Windows/Cygwin as well.