Skip to content

Instantly share code, notes, and snippets.

@Aricg
Created April 12, 2013 21:21
Show Gist options
  • Select an option

  • Save Aricg/5375218 to your computer and use it in GitHub Desktop.

Select an option

Save Aricg/5375218 to your computer and use it in GitHub Desktop.
watch a log file, echo anything it produces into a fifo
#!/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