以下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