Skip to content

Instantly share code, notes, and snippets.

@tomheng
Last active December 29, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomheng/7600651 to your computer and use it in GitHub Desktop.
Save tomheng/7600651 to your computer and use it in GitHub Desktop.
简单的日志监控程序
#!/bin/sh
sleep 5m
log=/var/log/php5.log
tail -Fn0 $log | \
while read line; do
echo $line | grep 'Fatal error'
if [ $? = 0 ]
then
pids=$(ps aux | grep $0 | grep -v 'grep' | awk '{print $2}')
php mail_error.php 'PHP Fatal error' "$line" # do what you want to do
sh $0 "$@" &
[ "$pids" != "" ] && kill -9 $pids
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment