Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created November 15, 2009 05:57
Show Gist options
  • Save tedheich/235041 to your computer and use it in GitHub Desktop.
Save tedheich/235041 to your computer and use it in GitHub Desktop.
run a command as soon as it occurs in a log file
tail -f file.log | grep --line-buffered "search pattern" | while read line
do
echo $line
done
# the line --line-buffered is key here, the read will fail without it
tail -f file.log | while read line; do if [[ $line == *search pattern* ]]; then
mycommand
fi; done
tail -f -n 0 logfile.out | nawk '/search-pattern/ {system("echo whatever")}'
# thet n -0 is essential, so that only new occurences will be matched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment