//View Tip #767
Similar Tips
» User input timeout
» Stream shell commands to Twitter
» Random xkcd comic
» Splitting arguments with read
» 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:

#!/bin/bash
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" \
    http://twitter.com:80/statuses/update.xml
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 »



Comments 

Add your comment

CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.

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

https://twitter.com/statuses/update.xml
https://identi.ca/api/statuses … update.xml
Posted 2009-04-30 10:07:41
bart9h
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
oxygen2
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
hashmonkey
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
John
hashmonkey: You can check for success of the previous command with '$?' so something like this will work right after the wget:

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

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit