Bash Script to Post to Twitter

By sterlo in Bash on 24/02/2009 at 22:44 (Old Revision)

Views: 92
Tagged: twitter, bash, cli, command, line, interface
URL: http://www.sterlinghamilton.com/blog/article/bash_script_to_post_to_twitter/

Starter:

Here is a quick/easy way to post to twitter from the command line interface.

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

user@river:~$ twitter Your Message Here

Main Course:

#!/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`[/code]
<p>Put the script in /usr/local/bin/<br />
Then it is as easy as:</p>
 
[code]
user@river:~$ twitter Your Message Here

Expand