Have you ever wanted to have your *nix shell access Twitter?
Using the RESTful API, you can achieve this. However, you would need to set up your instance as an app and then configure the API keys and all the what-nots. I personally try to avoid such hassle whenever possible.
So, I got this shell script for you (which is not originally mine, but has undergone a fair bit of modification by me) which achieves this:
#!/bin/bash #Twitter status update bot by http://360percents.com, http://mmnaseri.com #Author: Luka Pusic <pusic93@gmail.com> #Author: Mohammad Milad Naseri <m.m.naseri@gmail.com> #REQUIRED PARAMS username="TWITTER USERNAME" password="TWITTER PASSWORD" tweet="$*" #must be less than 140 chars #SETUP if test ! -e ~/.tweet; then mkdir ~/.tweet fi #EXTRA OPTIONS uagent="Mozilla/5.0" #user agent (fake a browser) sleeptime=0 #add pause between requests if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then echo "[FAIL] Tweet must not be longer than 140 chars!" && exit 1 fi if [ "$tweet" == "" ]; then echo "[FAIL] Nothing to tweet. Enter your text as argument." && exit 1 fi touch ~/.tweet/cookie.txt #create a temp. cookie file #INITIAL PAGE sleep $sleeptime initpage=`curl -s -b ~/.tweet/cookie.txt -c ~/.tweet/cookie.txt -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"` token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" />.*//'` #LOGIN sleep $sleeptime loginpage=`curl -s -b ~/.tweet/cookie.txt -c ~/.tweet/cookie.txt -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"` #HOME PAGE sleep $sleeptime homepage=`curl -s -b ~/.tweet/cookie.txt -c ~/.tweet/cookie.txt -L -A "$uagent" "http://mobile.twitter.com/"` #TWEET sleep $sleeptime tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" />.*//' | tail -n 1` update=`curl -s -b ~/.tweet/cookie.txt -c ~/.tweet/cookie.txt -L --sslv3 -A "$uagent" -d "authenticity_token=$tweettoken&tweet[text]=$tweet&tweet[display_coordinates]=false" "https://mobile.twitter.com/"` #LOGOUT logout=`curl -s -b ~/.tweet/cookie.txt -c ~/.tweet/cookie.txt -L -A "$uagent" "http://mobile.twitter.com/session/destroy"` rm ~/.tweet/cookie.txt
What this script does is fairly simple:
It opens up a a connection the mobile version of the twitter, submits a fake Login form, gains access to the page, and then posts all the input parameters collectively as your Tweet.
The problem currently is that you have to write in your twitter credentials inside the file. I might change that one day.
Dependencies
You will need to install “curl” on your machine to be able to run this.