Last active
December 29, 2015 02:29
-
-
Save tomheng/7600651 to your computer and use it in GitHub Desktop.
简单的日志监控程序
This file contains hidden or 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
#!/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