The Goal
Updating twitter status via shell script. The command used to send the HTTP request is POST a.k.a lwp-request (a perl script) that included in most linux distribution.
The Process
- Open your text editor i.e. gedit/geany/etc or even vi you are die hard fans of this editor.
- Copy and paste code below.
#!/bin/bash # TUNAME="lesstalkme" TUPASS="" TSTATUS="" TURL="http://twitter.com/statuses/update.xml" TDATA="source=LTME&status=" # print some fancy header :) echo "-----------------------------------------" echo " Twitter Status Updater" echo " http://www.less-talk-more-example.info/" echo "------------------------------------------" echo -n "Twitter Password: " read -ers TUPASS echo -e " Enter Twitter Status:" read TSTATUS # replace some characters ( I'm too lazy to replace all the characters :)) TSTATUS=`echo $TSTATUS | sed 's/ /%20/g'` # space => %20 TSTATUS=`echo $TSTATUS | sed 's/@/%40/g'` # @ => %40 TSTATUS=`echo $TSTATUS | sed 's/\//%2F/g'` # / => %2F TSTATUS=`echo $TSTATUS | sed 's/:/%3A/g'` # : => %3B TSTATUS=`echo $TSTATUS | sed 's/#/%23/g'` # # => %23 # now POST the data echo "" echo -n "Updating status..." echo "${TDATA}${TSTATUS}" | POST -C $TUNAME:$TUPASS $TURL | grep $TUNAME > /dev/null # check status # ------------ # successfull request always return XML format that containts our username # so we grep that to check the status if [ $? -eq 0 ]; then echo "DONE."; else echo "ERROR."; fi - Replace TUNAME value with your own username.
- Save to somewhere i.e. /tmp directory just for testing.
- Name it twitter.sh
- Open the shell terminal in GNOME System » Application » Terminal
- Go to /tmp directory and give execute permission to the file.
$ cd /tmp $ chmod +x twitter.sh - Execute the file, you'll be promted to enter twitter password and status.
$ ./twitter.sh - Fill it and voila!! your twitter status has been updated :).
Screencast
Download the Code
twitter.sh.zip via ziddu.com.
Size: 0.69kb
MD5 Checksum: f9d38c632430a617331cc4f8d298fcf1


1 komentar:
dicoba deh juragan! :D
Post a Comment