Howto : Twitter from Command Line…

This is a tutorial explaining how to post to Twitter using command-line in Linux, without needing to even open up your web browser….

First, install the curl package:

sudo apt-get install curl

Next, create a script anywhere in your $PATH, for example tweet.sh inside ~/bin, where ~ is your home directory (make sure ~/bin is included in your $PATH variable, in case echo $PATH doesn’t return it, edit ~/.bashrc and add a line like this: export PATH=/home/USER/bin/:$PATH)…

The script tweet.sh should contain the following:

 

#!/bin/sh

############EDIT THE FOLLOWING LINES...###########################
user="USERNAME"
pass="PASSWORD"
##################################################################

######################DO NOT EDIT BELOW THIS######################
tweet="${@}"

if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
    echo "FATAL: The tweet is longer than 140 characters!"
    exit 1
fi

curl -k -u ${user}:${pass} -d status="${tweet}" https://twitter.com/statuses/update.xml >/dev/null 2>&1

if [ "$?" == "0" ]; then
    echo "Successful tweet!"
fi

 

Replace USERNAME and PASSWORD with your Twitter username and password, and then make the script executable:

chmod 755 ~/bin/tweet.sh

And now test it.. Just use it as :

tweet.sh YOUR MESSAGE

This should be all…

If you don’t want to copy paste the code for tweet.sh then use the following link to download tweet.txt and RENAME it as tweet.sh