Home > Hacks > Giving Finger the Twitter

Giving Finger the Twitter

November 29th, 2009 rowan Leave a comment Go to comments

Commands with names that can be interpreted in a juvenile fashion seem to be a long standing tradition in the various Unix-like operating systems out there. One that seems to have fallen out of use is finger. So, to start the learning (and perhaps a little giggling) open a terminal and and let’s try fingering ourselves.

rowan@favabean:~$ finger rowan
Login: rowan Name: Rowan Merewood
Directory: /home/rowan Shell: /bin/bash
On since Sun Nov 29 15:58 (GMT) on tty7 from :0
4 hours 19 minutes idle
On since Sun Nov 29 16:42 (GMT) on pts/0 from :0.0
No mail.
No Plan.

At the end of the output you can see the rather cynical sounding “No Plan.” message. Since we hopefully do have a plan, let’s see what’s going on there. Straight-faced, type in:

man finger

Read through and you should find the excerpt:

~/.plan ~/.project~/.pgpkey
These files are printed as part of a long-format request. The .plan file may be arbitrarily long.

Let’s experiment with this in the classic way then:

rowan@favabean:~$ echo 'Hello, World!' > ~/.plan
rowan@favabean:~$ finger rowan
Login: rowan Name: Rowan Merewood
Directory: /home/rowan Shell: /bin/bash
On since Sun Nov 29 15:58 (GMT) on tty7 from :0
4 hours 30 minutes idle
On since Sun Nov 29 16:42 (GMT) on pts/0 from :0.0
No mail.
Plan:
Hello, World!

All simple enough, so why is it there? A little digging around will uncover a post on alt.folklore.computers in Origins of the finger command. He quotes an email from Les Earnest, the author of finger and it includes an explanation of the Plan feature:

Some people asked for the Plan file feature so that they could explain their absence or how they could be reached at odd times, so I added it. I found it interesting that this feature evolved into a forum for social commentary and amusing observations

This sounds familiar… almost as if filling in your .plan is the equivalent of answering the question “What’s happening?”

In which case, let’s link our old-school ’70s protocol up-to everyone’s favourite social network. Since we’re keeping the Unix theme, we’ll do it by piping a few commands together.

Fetch your status, substitute in your username for rowan_m:
http://twitter.com/users/show.xml?screen_name=rowan_m

Strip out everything except your update:
| grep "<text>"

Strip out the tags:
| sed 's/\s*<text>\(.*\)<\/text>\s*/\1/'

Dump that into your Plan:
> ~/.plan

Let’s string that all together and see what happens:

rowan@favabean:~$ curl http://twitter.com/users/show.xml?screen_name=rowan_m | grep "<text>" | sed 's/\s*<text>\(.*\)<\/text>\s*/\1/' > ~/.plan
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
104 1873 104 1873 0 0 4524 0 --:--:-- --:--:-- --:--:-- 8961
rowan@favabean:~$ finger rowan
Login: rowan Name: Rowan Merewood
Directory: /home/rowan Shell: /bin/bash
On since Sun Nov 29 15:58 (GMT) on tty7 from :0
4 hours 52 minutes idle
On since Sun Nov 29 16:42 (GMT) on pts/0 from :0.0
No mail.
Plan:
Piping some commands to other commands

There we go, my current status in my .plan. Obviously you don’t want to be running that manually every time, so as a last step you can add it into your crontab. For example, to set it up to run every five minutes use crontab -e and add the following:

# m h dom mon do command
*/5 * * * * curl http://twitter.com/users/show.xml?screen_name=rowan_m | grep "<text>" | sed 's/\s*<text>\(.*\)<\/text>\s*/\1/' > ~/.plan

This has been pretty quick and dirty, so feel free to point out optimisations. I’m sure we can get this down to 10 characters of Perl. ;)

Categories: Hacks Tags:
  1. November 29th, 2009 at 18:26 | #1

    Oh man… That *almost* sounds like a challenge….

    *fires up perl*

  2. November 29th, 2009 at 19:00 | #2

    @Ben Longden
    I had a feeling you might…

  3. Andrew Jacklin
    November 29th, 2009 at 20:25 | #3

    Perl? Python would be much more elegant.

  4. November 29th, 2009 at 20:35 | #4

    @Andrew Jacklin
    Then, sir, I invite thee to prove it!

  5. hosiawak
    November 29th, 2009 at 21:34 | #5

    Doesn’t work on my Windows 7 Ultimate Edition

  6. November 29th, 2009 at 21:37 | #6

    @hosiawak
    Ah, yeah… the Windows equivalent of sed is format. :P

  1. No trackbacks yet.