Created
April 12, 2013 21:21
-
-
Save Aricg/5375218 to your computer and use it in GitHub Desktop.
watch a log file, echo anything it produces into a fifo
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
| #!/bin/bash | |
| search_str="$1" | |
| pipe=/tmp/alert | |
| trap "rm -f $pipe" EXIT | |
| rm -f $pipe | |
| if [[ ! -p $pipe ]]; then | |
| mkfifo $pipe | |
| fi | |
| watch(){ | |
| tail -Fn0 /usr/local/nagios/var/nagios.log | \ | |
| grep -i --line-buffered "$search_str" | | |
| while read line; do | |
| echo "$line" > $pipe | |
| done & | |
| } | |
| watch "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment