以下bash脚本每天都会发送包含PHP错误日志的电子邮件。修改bash脚本以在读取文件时排除文本
#!/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="[email protected]"
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
我怎么能修改此脚本,以便它排除类似这样的所有错误:
[周四8月2日10点54分33秒2012] [错误] [客户12.345.67.89]目录 指数Options指令禁止: /无功/网络/域/公/模板/ IMG/
[周四8月2日11点25分35秒2012] [错误] [客户12.345.67.89]客户端通过服务器拒绝 配置: /var/www/domain/public/templates/sidebar .tpl
我更感兴趣的是:
- PHP的通知/警告/致命错误
- 文件不存在
你考虑'grep的-v'? – Bernhard 2012-08-04 08:43:26
备注:您可以在/ var/log/apache2/* - error.log中使用'for i而不是$ LIST来避免很多空白等问题。对于您的情况,这并不重要,但它很好养成正确处理空白的习惯。这也意味着你应该在for循环中使用“$ i”而不是简单的$ i。 – patrix 2012-08-04 09:24:36