Roman's Blog: OpenWRT Logging via Twitter


Have you ever thought of your router twitting status updates? E.g. if the connection goes down and comes back you are notified right away in a light-weight fashion.

Never?

Nevermind, here's how to do that:

  1. Create an account on twitter.
  2. Create a Basic authentication string with
    1 echo -n "$username:$password" | base64
  3. Use the following shell script, substituting $base64string with the string obtained in previous step:
    1 #!/bin/sh
     2 
     3 TWEET="status=$*"
     4 
     5 CONTENT_LENGTH=`echo -n $TWEET | wc -c`
     6 
     7 MESSAGE="
     8 POST /statuses/update.xml HTTP/1.1
     9 Host: twitter.com
    10 User-Agent: OpenWRT Twitter
    11 Accept: application/json, text/javascript, */*
    12 Accept-Language: en-us,en;q=0.5
    13 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    14 Content-Length: $CONTENT_LENGTH
    15 Authorization: Basic $base64string
    16 
    17 $TWEET"
    18 
    19 echo "$MESSAGE" | telnet twitter.com 80 > /dev/null 2>/dev/null
  4. Save it as /usr/bin/tweet and start using it right away.
  5. Set up some cron job, make it log something and... follow your router :)

You can follow my router, just in case :)

See also: