Advertisement
fduran

Linux monitor & react to event in log file

Jun 8th, 2011
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.53 KB | None | 0 0
  1. # Linux. Act upon an event in a log file
  2. # www.fduran.com
  3.  
  4. apt-get upgrade; apt-get install inotify-tools
  5.  
  6. # create file myalert.sh:
  7. # example finding Exception in tomcat log and sending email
  8.  
  9. #!/bin/bash
  10. while inotifywait -e modify /path/to/file.log; do
  11.   if tail -n1 /path/to/file.log | grep Exception; then
  12.     # your action here
  13.     echo "Exception in tomcat" |mail -s "Exception alert" email@example.com
  14.   fi
  15. done
  16.  
  17. # run with: bash myalert.sh > /dev/null 2>&1 &
  18. # test with:
  19.  
  20. echo "Exception" >> /path/to/file.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement