I like to work a lot on the command line of my Linux Boxes, and I am using Twitter a little bit these days, so I want to post from the command line.

I have checked the twitter page and have found that they already have the solution, with the files of their API

http://twitter.pbworks.com/API-Docs

So lets use curl to update the status of any account in Twitter, the single command is: <p class="codigo">curl –basic –user “ggarron:*****” –data-ascii “status=Arriving the office” “http://twitter.com/statuses/update.json”</p>

And easily this can be inserted into a bash script like this

#!/bin/bash
curl --basic --user "ggarron:*****" --data-ascii "status=$@" "http://twitter.com/statuses/update.json"

Be sure to replace the *** for your password in both cases and also ggarron for your own username in twitter.

The good thing is that you can create an account for every server you have, and make them tweet you when something happen, something like this:

#!/bin/bash
rm /home/user/backup/database.sql.1
mv /home/user/backup/database.sql /home/user/backup/database.sql.1
mysqldump -u user -p database > /home/user/backup/database.sql
if [ -f /home/user/backup/database.sql ]
then
    twitter "Backup OK"
else
    twitter "Backup Failed"
fi

Of course that is only a simple example, as even if some error exit mysqldump the file may be created anyway.