Sunday, March 23, 2008

Ubuntu: Twittering from the command line

I found this neat post in Hackszine recently. It shows a cool way of posting to twitter from your command line.

1.Let us convert it into a shell script. Open your favorite editor and create a file called twitter and enter these in it. (replace username and password with yours)

#!/bin/bash
curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml


2. Save the file and change the permission
$ sudo chmod u+x twitter


3. Now, let us try our cool twitter script
$ ./twitter "shell twitter script is up and running"


If you don't have curl, you'll need to get it via apt. It's simple..

$ sudo apt-get install curl


Once the twitter script finishes sending the post, it sends back an acknowledgment in form of an xml response with your account details.

Hope you had fun experimenting with twitter, I definitely did ;)

7 comments:

Anonymous said...

If you replace the $1 with $* in the script you can omit the quotes on the command line

Anoj said...

yeah, nice tip. Thanks a lot for sharing that

Anonymous said...

silvermonkey:~$ ./twitter "yeah, tweets from the command line"
403 Forbidden: The server understood the request, but is refusing to fulfill it../twitter: line 5: /update.xml: No such file or directory

it won't work anymore!?
or did I forget to touch update.xml?

Anoj said...

Hi Pete, update.xml lies on twitter's server ;)
Did you replace the username and password with yours, in the file?

Anonymous said...

Yes, I did. I even tried with my full email addy and still server understand but refuses.

Anonymous said...

It works now just needed to put it all on one line oeps. cool tip thanks Anoj

Anonymous said...

You have to escape a few chars to make this work as expected - take a look at my implementation of Command Line Twitter