Send a Twitter Message from the Unix Command Line

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!" \

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: "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:

curl -u mytwitterusername:mypassword -d status="$*" \

If you are not comfortable putting your password and username in the script, you can always make the script prompt for them. For example:


echo -n "Enter username: "

echo -n "Enter password: "
stty -echo
stty echo


curl -u $USERNAME:$PASSWORD -d status="$MESSAGE" \

For details about this API, see Twitter documentation:

Alvin Abad


6 thoughts on “Send a Twitter Message from the Unix Command Line

  1. @daniel: You do not make the tweets do that from any operating system. The twitter system does that for you – try looking at Ruby On Rails

    @Alvin: Please note that the user name and password will be visible in ps -ef output, which may be an issue on a multi user machine. If that is a worry then just omit the password in the interactive use case: curl will prompt for the password if a userid is given and a password is needed.

    If you wish to post programatically you should consider coding soemthing in ruby, python or perl to do this…

  2. does this still work? i seem to be getting an error every time.
    {“errors”:[{“code”:53,”message”:”Basic authentication is not supported”}]}

    does it need to be done using oauth keys now?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s