//View Tip #767
Similar Tips
» Stream shell commands to Twitter
» Random xkcd comic
» User input timeout
» Command line currency conversion
» Backup delicious bookmarks


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
I wrote a small script, I named it "tw" to update twitter from terminal:

echo "Your message please..."
read MSG
echo $MSG > characters
echo "Message length"
wc -c characters
echo "Password please..."
read -s PW
wget --keep-session-cookies --http-user=your.email@address.here --http-password=$PW \
    --post-data="status=$MSG" \
echo "Message posted."

This can also be used to update identi.ca (the open twitter alternative) by replacing the twitter url with 'http://identi.ca/api/statuses/update.xml'.

View Comments »


Add your comment

Comments are currently disabled
Both of these commands should also work with https, just update the URLs to:

https://identi.ca/api/statuses … update.xml
Posted 2009-04-30 10:07:41
You should include a " || exit" after wget, so the "Message posted." won't be printed if wget fails.
Posted 2009-04-30 12:03:31
Cambell Spong
Could strip out:

  echo $MSG > characters
  echo "Message length"
  wc -c characters

and replace with just:

  echo "Message Length: ${#MSG}"

Reduces line number and removes need for 'characters' file.
Posted 2009-05-03 12:59:09
if i wanted to skip the prompt for the message and tweet right from the command line, would i use $@ in place of $MSG?

ie, calling tw this is my tweet would then only ask for the password?
Posted 2009-05-04 06:56:38
Cambell Spong
It would work but you would have to escape some special bash characters. ie \' \" \`, etc.
Otherwise bash would interpret them.
Posted 2009-05-04 17:59:03
Is there a way to verify that the wget worked? Wanted to show a message only if it didn't work, ie the password was wrong.
Posted 2009-05-16 15:38:06
hashmonkey: You can check for success of the previous command with '$?' so something like this will work right after the wget:

wget ...
if [ $? = 0 ]
 echo success
 echo fail
Posted 2009-05-18 09:18:44

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit