WARNING: THE INSTRUCTIONS DESCRIBED HERE NO LONGER WORKAs of August 31, 2010, Twitter no longer supports basic HTTP authentication. And unfortunately, this blog post explains how to use curl, with basic HTTP authentication, to tweet from a command line. As described
here, you must now use OAuth to interact with the Twitter API. As a result, the instructions here no longer work, and have been left in place only for archive purposes.

I recently stumbled across
this awesome post via
Twitter that explains how to Tweet from the command line like a pro using
curl. I tried it, and sure enough, it works! If you want to Tweet a message from the command line using curl, here's how:
#/> curl -u mytwitterusername:mypassword \
-d status="from the cmd line!" \
http://twitter.com/statuses/update.json
Even cooler, if you want to pipe output into a Tweet (
like your system uptime from the "uptime" command), you can run the following:
#/> curl -u mytwitterusername:mypassword \
-d status="my uptime:`uptime`" \
http://twitter.com/statuses/update.json
Note that if you are
behind a corporate firewall at work, you will need to tell curl to use an HTTP web-proxy to communicate with the outside world. This can be done using the -x option like so:
#/> curl -u mytwitterusername:mypassword \
-d status="from the cmd line!" \
-x web-proxy.example.com:8088 \
http://twitter.com/statuses/update.json
Or, if you wanted to pipe the output of a command into a Tweet, you can do so using the -d @- arguments which asks curl to read the POST input from <STDIN>. Here's an example of piping the output of "df -h /" into a Tweet (
to Tweet the usage of my root disk):
#/> echo "status=`df -h /`" | \
curl -u mytwitterusername:mypassword \
-d @- \
-x web-proxy.example.com:8088 \
http://twitter.com/statuses/update.json
For the HP-UX Tweeps out there (
@HP_UX) ...
If you happen to be using a system without
curl, you can easily install it. On HP-UX,
curl can be installed using the
HP-UX 11i Internet Express package available from hp.com (
HP-UX 11i v2 or
HP-UX 11i v3). As root on your HP-UX box, use the
swinstall command to install your freshly downloaded .depot ...
swinstall -s /path/to/depot/internet_A.12.00.013_HP-UX_B.11.23_IA_PA.depot
Enjoy!