Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


Can I send Twitter updates from the command line?

I'm becoming a big Twitter fan, but as a Linux user, I find it darn frustrating that most of the apps out there are for Mac and Windows users. I mean, I'm used to it, but is there at least some way to get to Twitter from the command line?


Dave's Answer:

Actually, there are a number of interesting Linux apps for Twitter, now that you mention it. Check out both the Twitter Fan Wiki and the Twitter download page for some of your options.

Since Twitter has a nice, albeit simple, API, there are also some methods that you can use to access Twitter from the command line, as you seek. Of course, monitoring the twitterstream, public or otherwise, is difficult because the output formats are all a bit tricky to parse, but certainly adding your own Twitter status updates is straightforward.

The trick is to use the terrific utility curl. Let me show you the basic command line invocation:

curl --basic --user "$user:$pass" --data-ascii \
    "status=`echo $@ | tr ' ' '+'`" "http://twitter.com/statuses/update.json"

Obviously, you'll need to set your Twitter username and password in the script (which means that the script won't be secure) which you can do like this:

user="DaveTaylor"
pass="I'm not going to show you here!"

Then the sequence of "$@" is simply the command arguments you've specified to the script. So if it's called "send-twitter" you could send an update on the command line as simply as:

$ send-twitter Watching Shrek, completely unmotivated to go outside today

That should get you going with the scripting. In terms of how to script monitoring the Twitterstream itself, that's a topic I'll be tackling in my Linux Journal shell scripting column in a month or two. Keep an eye out for it at the newsstand!

Finally, please be aware that I have a variety of twitter help here, and you can also monitor my twitterstream if you'd like too! Tip o' the hat to Binny, who originally presented this basic script idea on his blog.


More Useful Shell Script Programming Articles:
✔   Secretly capture screenshots on my Mac?
When I used to work on a Linux system, there was a utility we had that would let me take screen captures every...
✔   Parsing "id" strings in a Shell Script?
Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the...
✔   Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔   Script to test line lengths for Twitter compatibility?
I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because...
✔   Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: Shell Script Programming   (Article 7797, Written by )
Tagged: shell scripting, twitter
Previous: How do I create my own Google Profile?
Next: How do I search the patent database?




Reader Comments To Date: 3

vergil66 said, on December 28, 2007 2:54 PM:

Dave--Thanks for the article and I'm happy that you continue to cover shell script stuff.
Peace,
Chris

Binny V A said, on May 11, 2008 12:35 PM:

Hey, thanks for the mention.

Shai said, on July 17, 2009 2:56 PM:

There's also the twitter gem, and then you can run via the command line:

shai@comp ~: $ twitter

Usage: twitter [options]

Available Commands:
- post
- p
- timeline
- friends
- friend
- followers
- follower
- featured
- important
- follow
- leave
- d

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.