I was having a very slow morning at work and I started experimenting with sending tweets from the command line in Linux. I realize this is a little silly and there are plenty of good twitter apps out there but I found it amusing so I decided to post it.
NOTE: You must have curl installed for this to work but I believe its standard on most Linux distros.
The first way to do it is just a one liner:
curl -u user:pass -d status="Here is my tweetl" http://twitter.com/statuses/update.xml
The only problem with the one liner is that it doesnt check to make sure your tweet is 140 chars or less and it also gives a bunch of xml output after it posts to the twitter API.
So I decided to whip up a quick shell script:
#!/bin/bash
host=http://twitter.com/statuses/update.xml
max=140
echo "Please enter your twitter username: "
read user
while [ "$user" == "" ];
do
echo
echo "Please enter your twitter username: "
read user
done
echo "Please enter your password: "
read passwd
while [ "$passwd" == "" ];
do
echo
echo "Please enter your password: "
read passwd
done
echo "Enter a status update (140 chars max): "
read status
while [ "$status" == "" ];
do
echo
echo "Enter a status update (140 chars max): "
read status
done
while [ ${#status} -gt $max ];
do
echo
echo "Your status is longer then 140 chars"
echo -en "nEnter a status update (140 chars max): "
read status
done
curl -u $user:$passwd -d status="$status" $host > /dev/null 2>&1
Just save the script and call it something like twitter_shell.sh and make it executable:
chmod 755 twitter_shell.sh
Thats it, now you can run the script when you are working on Linux servers and make twitter updates when you should be working!
|
|
|
|




Entries (RSS)
Here is a bash script to post to Twitter from the command line on Linux and Mac:
http://360percents.com/posts/command-line-twitter-status-update-for-linux-and-mac/
[Reply]