Tweeter – The little bash-script that can

A rough and tumble bash script to send updates to Twitter from the commandline. The script also parses the returned JSON (with the finesse of a blunt chainsaw), extracts the message ID and stores it in an Sqlite database together with the text of the tweet.

This requires curl a very powerful program for moving files around the internet using whatever protocol may be necessary and which should really be installed on every system. Believe me kids – curl beats the shit out of everything else in the field of file haulage.

read -p "Tweet: " rtweet
REP=$(curl -s -S -u username:password -d status="$tweet"\
EXP=$(expr match "$REP" ".*id\":\([0-9]*\)")
sqlite3 ~/dbs/tweets<<EOF
insert into mems values("$EXP","$tweet");

Adapt to your needs by changing values to those befitting your system, make executable and stick it in /usr/local/bin/. Then whenever you want to fire off a quick tweet you can call it up enter your tweet and the world receives another superfluous message :-). Enjoy!

Watch this space for a version that sends URLs to Bitly for shortening and then incorporates them into your tweet. I have a working version, but that is sooo like two kludges welded together that I don’t want to show it yet.

Caution: If you are on a box that is shared by several people, you should not stick this in /usr/local/ or anybody can use it to tweet under your name. Either adapt it to prompt for a username and password, or put it in a save location within your home directory that you can then add to your path (see ‘man bash’ for more help).

The shortURL for the permalink to this post:

In the next installment on the way to a Twitter client in bash Tweeter catches featuritis.


About dozykraut

Proud member of Hillbilly's on Linux, promoting open source redneckism in remote parts of the Milky Way.
This entry was posted in Bash and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s