Skip to content

Instantly share code, notes, and snippets.

@hanynowsky
Forked from fduran/gist:1870502
Last active August 29, 2015 14:12
Show Gist options
  • Save hanynowsky/d20f982d3fed4dd31637 to your computer and use it in GitHub Desktop.
Save hanynowsky/d20f982d3fed4dd31637 to your computer and use it in GitHub Desktop.
# 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