Kỹ Thuật Máy tính

Nghiên cứu – Phát triển – Rút ngắn khoảng cách

Twitting từ linux shell

Đăng bởi dongthao on Tháng Chín 30, 2008

Vì lười dùng các chương trình giao diện cũng như mở trình duyệt, tôi vừa viết một script nhỏ xíu để post twitter từ shell của linux (sử dụng wget). Nội dung của nó như sau:

#!/bin/bash
## Provide your twitter username and password here
username=
password=
##

message=”"
if [ $# -gt 0 ]; then
while [ "$1" != "" ]; do
message=”${message} ${1}”
shift
done
else
echo “Enter your message as the parameter.”
fi
echo “POSTING” $message
wget -q –delete-after –user=$username –password=$password –post-data status=”${message}” http://twitter.com/statuses/update.xml

echo “DONE.”

Save đoạn script trên vào 1 file sau đó iền username và password của bạn (đừng lo, tôi không hề biết tí gì về thông tin này đâu :D ) đặt tên là twitsh. Dùng lệnh chmod để có thể thực thi file này:

$ chmod +x twitsh

Để post message ” Reading newspaper now” lên twitter.com ta gõ lệnh:

$ ./twitsh Reading newspaper now

Nếu lười … hơn tôi, bạn cũng có thể tải script tôi viết sẵn tại đây :p, điền username, password vào, chmod và sử dụng ngay.

Chúc vui.

3 phản hồi tới “Twitting từ linux shell”

  1. nano đã nói

    want more fun? try http://www.sakana.fr/blog/2007/03/18/scripting-twitter-with-curl/

  2. dongthao đã nói

    Thanks nano, link rất hữu ích.

  3. phuong đã nói

    #!/bin/bash
    ## Provide your twitter username and password here
    username=
    password=
    ##

    message=””
    if [ $# -gt 0 ]; then
    while [ "$1" != "" ]; do
    message=”${message} ${1}”
    shift
    done
    else
    echo “Enter your message as the parameter.”
    fi
    echo “POSTING” $message
    wget -q –delete-after –user=$username –password=$password –post-data status=”${message}” http://twitter.com/statuses/update.xml

    echo “DONE.”

Để lại hồi âm

XHTML: Bạn có thể sử dụng những thẻ sau: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>