Home > Resources, Tips and Tricks, blogging > Look mawh, I tweeted in the command line

Look mawh, I tweeted in the command line

Have you ever wanted a quick and easy way to post to twitter within your shell scripts, or viva a cronjob? Well for those of you that follow my tweets you’ve experienced this script in action. I give to you tweetr…Just copy and paste to a new text file and chmod +x on linux, unix and mac.

#!/bin/sh
# tweetr version 1.9
# a twitter client in cli
# (C)2008 Dwight Spencer (Den Zuko)
# All Rights Reserved.
#############################################################################
# TODO:
#  * add in checking for wget vs curl and gracefully drop to lwp-get
#  * add in getopt support for username and password, also for https or http
# Change Log:
#  * added pwsafe support

usage() {
echo "Usage: `basename $0` " && exit 0
}

die() {
echo "Opps something went wrong" && exit 1
}

[ [ $# -lt 1 ] && usage
MSG=$1

AGENT=$(which curl)
PWSAFE=$(which pwsafe)
[ $? == 1 && die
if [ -f $HOME/.tweetrc ]; then
auth=`cat $HOME/.tweetrc`
else
echo -n "Twitter Username: " && read -p "Twitter Username: " user

if [ =f $HOME/.pwsafe.dat ]; then
pass=$(${PWSAFE} -quE twitter.$user)
else
echo -n "Twitter Password: "
stty -echo && read pass && stty echo
fi
auth=${user}:${pass}"
echo $auth > $HOME/.tweetrc
fi

xmlrpc="https://$auth@twitter.com/statuses/update.xml"
$AGENT -d status="${MSG}" $xmlrpc 2>&1 1>/dev/null

Links

You can find future releases of this and many more scripts, hints, and tips only here at The Teachings of Master Denzuko. Also, don’t forget to tell us what you think or how you’ve used this, give your shout out in the comments below.

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.