Giving Finger the Twitter
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.
1 2 3 4 5 6 7 8 | 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:
1 | man finger |
Read through and you should find the excerpt:
1 2 | ~/.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:
1 2 3 4 5 6 7 8 9 10 11 | 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, substituting in your username for rowan_m:
1 | http://twitter.com/users/show.xml?screen_name=rowan_m |
Strip out everything except your update:
1 2 | | grep "<text>" </text> |
Strip out the tags:
1 2 | | sed 's/\s*<text>\(.*\)< \/text>\s*/\1/' </text> |
Dump that into your Plan:
1 | > ~/.plan |
Let's string that all together and see what happens:
1 2 3 4 5 6 7 8 9 10 11 12 | rowan@favabean:~$ curl -s http://twitter.com/users/show.xml?screen_name=rowan_m | grep "<text>" | sed 's/\s*</text><text>\(.*\)< \/text>\s*/\1/' > ~/.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 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 </text> |
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:
1 2 3 | # m h dom mon do command */5 * * * * curl -s http://twitter.com/users/show.xml?screen_name=rowan_m | grep "<text>" | sed 's/\s*</text><text>\(.*\)< \/text>\s*/\1/' > ~/.plan </text> |
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. ;)
November 29th, 2009 - 18:26
Oh man… That *almost* sounds like a challenge….
*fires up perl*
November 29th, 2009 - 19:00
@Ben Longden
I had a feeling you might…
November 29th, 2009 - 20:25
Perl? Python would be much more elegant.
November 29th, 2009 - 20:35
@Andrew Jacklin
Then, sir, I invite thee to prove it!
November 29th, 2009 - 21:34
Doesn’t work on my Windows 7 Ultimate Edition
November 29th, 2009 - 21:37
@hosiawak
Ah, yeah… the Windows equivalent of sed is format. :P
November 26th, 2010 - 10:27
Might want to use the -silent option, it could start filling up your mailbox!
July 3rd, 2011 - 23:17
Noted and updated!
July 3rd, 2011 - 13:07
curl http://twitter.com/users/show.json?screen_name=rowan_m | php -R ‘print json_decode($argn)->status->text;’ > ~/.plan