Skip to content

Instantly share code, notes, and snippets.

Created August 3, 2009 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/160422 to your computer and use it in GitHub Desktop.
Save anonymous/160422 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# gtail.sh - tail a file, show growl when strings match
# uses growlnotify, the Growl command line tool: http://growl.info/documentation/growlnotify.php
#you might need to change where growlnotify lives
growl_notify="/opt/local/bin/growlnotify"
function usage() {
echo "gtail [-f file] <regex>"
echo "tail a file and make Growl messages for lines matching <regex>"
echo "example: cat file.log | gtail.sh Error"
exit
}
case $# in
1) msg="stdin"; file="-"; re=$1 ;;
2) msg=$1; file=$1; re=$2 ;;
*) usage ;;
esac
cat $file | while read line; do
match=$(echo "$line" | /usr/bin/sed -n /"$re"/p)
if [ -n "$match" ]; then
"$growl_notify" -t "$msg" -m "$match" -w &
fi
echo $line
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment