How to tweet from command line

First, make sure you have "curl" install on your machine.
if not, install it with
"yum" or "apt-get".










Create a new script with your favorite editor, i like vi
# vi /usr/bin/tweet (as root user)
and copy the next lines to it.

#!/bin/sh

tweet="${@}"
user="USER"
pass="PASSWORD"

if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
echo "FATAL: The tweet is longer than 140 characters!"
exit 1
fi

curl -k -u ${user}:${pass} -d status="${tweet}" https://twitter.com/statuses/update.xml >/dev/null 2>&1

if [ $? == "0" ]; then
echo "Successful tweet!"
fi

Change the USER to your user name and the PASSWORD to your twitter password.
save and run the command:
# chmod +x /usr/bin/tweet

that's it.

run from your command line
# tweet "Testing tweet sctipt"

and you are twitting.

2 comments:

  1. Great script, but each time I try I get the following:

    [: 16: 127: unexpected operator

    Anything I may have done wrong?

    ReplyDelete
  2. Hi Chris,
    Thanks for your comment.
    I changed the script a bit, please try it now and let me know if it works for you.
    Regards.

    ReplyDelete