Bash Tweet Script

posted Sep 8, 2010, 9:29 PM by David Cole
A script I found on the internet for tweeting from bash. 

Original Link: http://code-cookbook.com/entry/75/bash-script-to-post-to-twitter



#!/bin/bash

# Login information.
USERNAME="username"
PASSWORD="password"
URL=http://twitter.com/statuses/update.xml

# Check message length.
if [ ! -n "$1" ]; then
        echo "Message not long enough"
        exit
fi

# Check message length again.
message="$@"
maxlen=140;
len=`echo ${#message}`

if [ $len -gt $maxlen ]; then
        echo "Your message was longer than 140 characters...";
fi

# Post to Twitter.
result=`curl -u $USERNAME:$PASSWORD -d status="$message" $URL`


Note: 9/September/2010 - This worked before twitter changed to OAuth for tweeting.  So it's pretty much useless now.
Comments