Created
August 3, 2009 08:33
-
-
Save anonymous/160422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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