Created
November 15, 2009 05:57
-
-
Save tedheich/235041 to your computer and use it in GitHub Desktop.
run a command as soon as it occurs in a log file
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
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 |
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
tail -f file.log | while read line; do if [[ $line == *search pattern* ]]; then | |
mycommand | |
fi; done | |
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
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