以下 bash 脚本每天发送一封包含 PHP 错误日志的电子邮件。
#!/bin/bash
# phperrlog v1.0
# by vladimir prelovac http://www.prelovac.com/vladimir/
#
# parse error logs on your server and send you daily updates to email
# configure options
EMAIL="tech@domain.com"
WORKDIR="/var/scripts"
TAIL=50 # number of entries to send
# IGNORE="/backup" # path to ignore
# script starts 'ere
cd $WORKDIR
rm phperrlog.txt 2>/dev/null
LIST=$(ls /var/log/apache2/*-error.log)
today=$(date +%Y-%m-%d)
for i in $LIST
do
if [ -f $i ]; then
time=$(date -r $i +%F)
if [ "$time" == "$today" ]; then
echo $i >>phperrlog.txt
echo "---------------------------------" >>phperrlog.txt
tail -n $TAIL $i >>phperrlog.txt
echo -e "\n\n\n\n" >>phperrlog.txt
fi
fi
done
if [ -f phperrlog.txt ]; then
mail -s "PHPERRORLOG SCRIPT: server error logs - $today" $EMAIL < phperrlog.txt
fi
如何修改此脚本以排除与此类似的所有错误:
[Thu Aug 02 10:54:33 2012] [error] [client 12.345.67.89] Options 指令禁止的目录索引:/var/www/domain/public/templates/img/
[2012 年 8 月 2 日星期四 11:25:35] [错误] [客户端 12.345.67.89] 客户端被服务器配置拒绝:/var/www/domain/public/templates/sidebar.tpl
我对以下内容更感兴趣:
- PHP 通知/警告/致命错误
- 文件不存在