Twitter from the Command Line


Scimon linked to this article.

There is an Updated version

I've added some checks and split the username and password into a separate, secure, file.

/usr/local/bin/cl-twit


#!/bin/bash
# Source http://www.fsckin.com/2008/03/19/twittering-from-the-command-line/
# 0.0.1 - initial adaptation
# 0.0.2 - protect against errors when using: cl-twit "This isn't going to cause an error."
#        The double quotes are needed because of the ' which introduces spaces into $1
if [ -z "$1" ]; then
    echo You have to say SOMETHING!
    exit
fi
TWITFILE=~/.twitter
TWITFILESECURE=unknown
if ( stat $TWITFILE | grep '^Access: (..00/' > /dev/null ) ; then
    TWITFILESECURE=yes
fi
if [ $TWITFILESECURE != "yes" ]; then
    echo The file $TWITFILE should not be world readable
    echo Try: chmod go-rwx $TWITFILE
    exit
fi
. $TWITFILE
if [ -z $TWITUSER ]; then
    echo TWITUSER not set in $TWITFILE
    exit
fi
if [ -z $TWITPASS ]; then
    echo TWITPASS not set in $TWITFILE
    exit
fi
curl --basic --user "$TWITUSER:$TWITPASS" \
    --data-ascii "status=`echo $@|tr ' ' '+'`" \
    "http://twitter.com/statuses/update.json"

You will need to create a file ~/.twitter like the following:


TWITUSER=kemitix
TWITPASS=my-password

Make sure only you can read it:

chmod go-rwx ~/.twitter

This makes it nice and safe to install on a multi-user machine. Assuming you trust root.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <div> <dl> <dt> <dd> <img> <p> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
9 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Project navigation

Archives

November 2008
MonTueWedThuFriSatSun
272829303112
3456789
10111213141516
17181920212223
24252627282930

My Podiobooks

Syndicate

Syndicate content