//View Tip #768
Similar Tips
» Bash
» See your favorite commands
» Overwrite a file with zeroes
» Deleting whole words on a bash command line
» Changing file extensions

 

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
When I read the tip yesterday (Twitter from the terminal), I thought it would be fun to set something up to tweet all the commands I enter. After a bit of playing around I have come up with the following:

First you'll need to create a script, it doesn't matter what you call it, just remember the name and path to it for later.

#!/bin/bash
read MSG
echo $MSG > characters
length=$(wc -c characters | sed 's/^[^0-9]*\([0-9]*\)[^0-9]*$/\1/')
if [ $length -le 140 ]; then
  wget -q --keep-session-cookies --http-user=YOURUSER --http-password=YOURPASS \
    --post-data="status=$MSG" \
    https://twitter.com/statuses/update.xml;
fi

You'll need to replace YOURUSER and YOURPASS as appropriate, and if you prefer to use identi.ca then change the twitter url to https://identi.ca/api/statuses/update.xml

Next run the following command, changing details at the end for the script you just created (note this does require you to use bash):

export PROMPT_COMMAND='echo "$(history 1)" | sed "s/^ *[0-9]* *//" | /path/to/script.sh'


Now every command you type will be sent to twitter! To turn this off, just run "export PROMPT_COMMAND=''" or logoff. Of course this isn't really a good idea to do all the time, though it is fun! Also remember that Twitter will block accounts that post over 100 updates per hour.

An example of the results can be seen here: https://twitter.com/ShellStream


View Comments »




Comments 

Add your comment

Comments are currently disabled
I'm terribly paranoid about storing passwords of any kind on disk..  Might I suggest using ramfs to store the password, and modifying your script to get it from there?

I do something similar for other apps..  

Check it out:

http://pastebin.com/fd0a4d01

You'll have to run it with sudo.  Then you could access the pass via `cat /tmp/app_pass.txt`

Then you don't have the password on disk and when you reboot, it goes away.
Posted 2009-05-01 16:12:41

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit