Bash Script to Post to Twitter

May 25 20080 comments | post comment

Here is a quick/easy way to post to twitter from the cli.

#!/bin/bash

#############################################

USERNAME="your@email.com"
PASSWORD="password"
URL=http://twitter.com/statuses/update.xml

#############################################

if [ ! -n "$1" ]
then
echo "Message not long enough"
exit
fi

message
="$@"

maxlen=140;
len=`echo ${#message}`

echo
$len;

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

result
=`curl -u $USERNAME:$PASSWORD -d status="$message" $URL`L`

Put the script in /usr/local/bin/
Then it is as easy as:

user@river:~$ twitter Your Message Here

Update:
Updated the script. No longer using expr to get the length of message. I was getting errors in OS X. 

Comments

Leave a Comment

Allowed / Requried

Only these elements are allowed in submitted comments:

  • <a href="http://www.mysite.com/">my site</a>
  • <img src="http://www.mysite.com/myimage" alt="image" />
  • <blockquote>quote</blockquote>
  • <em>my emphasized text</em>
  • <strong>my bold text</strong>
  • <code>my code</code>

* = Required fields

Name:

Email:

Location:

URL:

Remember my personal information

Please enter the word you see in the image below: