Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
简单的日志监控程序
#!/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