Skip to content

Instantly share code, notes, and snippets.

@fduran
Created February 20, 2012 18:26
Show Gist options
  • Save fduran/1870502 to your computer and use it in GitHub Desktop.
Save fduran/1870502 to your computer and use it in GitHub Desktop.
Linux monitor & react to event in log file
# 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@example.com
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