Tweeting from the CLI

There are several Twitter clients for linux. Out of the three I have tried only one really worked and all of them were GUI based. After doing some reading up on curl and bash scripting I decided to get my feet wet by hacking together a script to update twitter from the command line. If you don’t provide any input to update your status it simply prints the latest twenty updates from your friends feed. Hopefully someone finds this useful:

#!/bin/bash

# A Simple script to update your twitter feed. If you don't provide any input to update your status it prints the last twenty updates from your friends feed

TWEET=$1
USERNAME=yourUsername
PASSWORD=yourPassword

if [ -z "$1" ]; then
echo No status update entered. Showing last twenty updates:
curl --basic --silent --user $USERNAME:$PASSWORD --get http://twitter.com/statuses/friends_timeline.xml | sed --quiet --expression='s/\(.*\)/\1/p' --expression='s/\(.*\)/\1/p'
exit
fi

curl -s -u $USERNAME:$PASSWORD http://twitter.com/statuses/update.xml -d status="$TWEET" > /dev/null
echo Status updated.

exit


About this entry