If you are a fan of Twitter and also a Unix user who spends most of your waking hours on the command line, wouldn’t it be nice if you can send your Twitter update from the Unix command line? Twitter has an API that makes sending from the Unix command line easy. All you need is the curl command (which should be available nowadays on most Unix systems) and you can fire up your Twitter message like this:
curl -u mytwitterusername:mypassword -d status="the server is up!" \ http://twitter.com/statuses/update.json
Note: The command above should be all in one line.
Easy, isn’t it?
But you might say, “Wow, that’s a lot of typing to do. BTW, is that my password in clear text?”
Well, this is where Unix scripting comes to the rescue. You can easily wrap this in a shell script and your usage could be as simple as this:
twitter.sh "the server is up!"
The rest are inside the script where you can hide your username and password by making sure that only you can read it. For example:
#!/bin/sh curl -u mytwitterusername:mypassword -d status="$*" \ http://twitter.com/statuses/update.json
If you are not comfortable putting your password and username in the script, you can always make the script prompt for them. For example:
#!/bin/sh echo -n "Enter username: " read USERNAME echo -n "Enter password: " stty -echo read PASSWORD stty echo echo MESSAGE="$*" curl -u $USERNAME:$PASSWORD -d status="$MESSAGE" \ http://twitter.com/statuses/update.json echo
For details about this API, see Twitter documentation: http://apiwiki.twitter.com/REST+API+Documentation