Created
February 20, 2012 18:26
-
-
Save fduran/1870502 to your computer and use it in GitHub Desktop.
Linux monitor & react to event in log file
This file contains 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
# Linux. Act upon an event in a log file | |
# www.fduran.com | |
apt-get upgrade; apt-get install inotify-tools | |
# create file myalert.sh: | |
# example finding Exception in tomcat log and sending email | |
#!/bin/bash | |
while inotifywait -e modify /path/to/file.log; do | |
if tail -n1 /path/to/file.log | grep Exception; then | |
# your action here | |
echo "Exception in tomcat" |mail -s "Exception alert" [email protected] | |
fi | |
done | |
# run with: bash myalert.sh > /dev/null 2>&1 & | |
# test with: | |
echo "Exception" >> /path/to/file.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment