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