#!/bin/sh # Inspired by http://www.zdnet.co.uk/athome/misc/toot/ # (Link long dead. Use the Internet Archive Wayback Machine & go back to 2001) # See also this commentary: http://cectic.com/177.html # Ways to use toot: # toot "thing" # toot "thing 1" "thing 2" # |toot #GET="fetch -q -o -" GET="get_internal" #values for google: URL="http://www.google.com/search?q=" SEPERATOR="+" GREPFOR="[0-9] of (about )?[0-9]" SEDFOR=".*of (about )?([,0-9]+) for .*" SEDNUM=2 wait=0 while getopts i: opt;do case $opt in i) wait=$OPTARG;; esac done shift `expr $OPTIND - 1` get_internal () { #assume protocol == http host=`echo "$@" | sed s%http://%% | sed s%/.*%%` path=`echo "$@" | sed s%http://[^/]*%%` { echo "GET $path HTTP/1.0" echo "Host: $host" echo "Accept: text/html, text/plain" echo "Accept-Language: en" echo "User-Agent: toot/1.1" echo } | nc $host 80 } me="$0" case $# in 0) # Pipe mode { while read line;do echo -e `$me "$line"`\\t$line sleep $wait done } | sort -n ;; 1) # Functional mode result=`$GET "$URL\`echo $1|sed s/\ /$SEPERATOR/g\`" 2>/dev/null|egrep "$GREPFOR"|head -n1|sed -r "{ s%$SEDFOR%\\\\$SEDNUM% s%,%%g }"` if [ -z "$result" ];then echo 0 else echo "$result" fi ;; *) # Foreach mode for thing in "$@";do echo -e `$me "$thing"`\\t$thing sleep $wait done | sort -n ;; esac