Tag Archives: shell


Updating Your Twitter Status From a Script

Just a quick little script modified from the one found here http://cutup.org/anize/?twitter_bash_curl

I hardcoded the username/password and stripped out the “friends” statuses. For my purposes (http://appliedresearchwi.com headline) I only need “my” current status.

The script is run from crontab as follows:


*/5 * * * * /home/zachpeters/appliedresearchwi.com/etc/twitter.sh > /home/zachpeters/appliedresearchwi.com/etc/twitter.status

Code – note the “username” and “password” need to be changed:

#!/bin/bash
# Originally from - http://cutup.org/anize/?twitter_bash_curl
function getlastpost {
    curl -u username:password 3 --connect-timeout 5 -s -n $1 | awk '
        { sub(/^[^>]*>/,”",$0) }
            /text/ {
                sub(/<[^<]*>$/,”",$0)
                m=$0
            }
            /relative/ {
                sub(/<[^<]*>$/,”",$0)
                at=$0
            }
            /_name/ {
                sub(/<[^<]*>$/,”",$0)
                #print $0 ” : ” m ” [" at "]”
                print $0 ” :: ” m
            }
    '
}
getlastpost http://twitter.com/statuses/user_timeline.xml?count=1

I have found this method to be very useful

for automated scripts.  I will run cron jobs and then get updated via twitter.  It makes sense, its simple, its quick, it comes right to my phone and I know instantly that things are okay.  This could easily be worked into other monitoring/alerting schemes when a full email is too much overhead.

Good idea? Twitter has been know to have some down-time in the past so I wouldn’t count on it for mission-critical stuff.  Is this something you would use? What other ways have you extended twitter?

Share