1.功能
实现检查日志上传的是否正确
实现在不正确时自动重新上传
实现在重新上传错误后,再通过短信或邮件报警
2.需要资源
短信报警服务器(短信猫)
3. 程序
#! /bin/sh
YESTER=`date -d "yesterday" +%Y.%m.%d`
OLDDAY=`date +%Y.%m.%d -d '2 day ago'`
#报警程序
alarm() {
for errhost in `cat /tmp/logerr.log|awk '{print $2}'`
do
wget "= ${errhost} put error" -o /dev/null&
rm -rf ./*alert.php*
done
}
#日志检查程序
check() {
for i in `cat /opt/sbin/monitor/dirlist.txt|awk '{print $1}'`
do
NUM1=`find ${i} -name "*access_${YESTER}*"|wc -l`
NUM2=`find ${i} -name "*access_${OLDDAY}*"|wc -l`
INFO=`cat /opt/sbin/monitor/dirlist.txt|grep ${i}`
if [ "${NUM1}" != "${NUM2}" ]
then
echo ${INFO} >>/tmp/logerr.log
fi
done
}
#日志重新上传程序,这里需要在传日志的服务器上部署日志上传脚本
ftprepeat(){
for errhost in `cat /tmp/logerr.log|awk '{print $2}'`
do
ssh -lroot ${errhost} "/bin/sh /opt/sbin/reputlog.sh"
done
}
check ;
if [ -f /tmp/logerr.log ]
then
ftprepeat ;
rm -rf /tmp/logerr.log
fi
sleep 300;
check ;
if [ -f /tmp/logerr.log ]
then
alarm ;
rm -rf /tmp/logerr.log
fi
阅读(1183) | 评论(0) | 转发(0) |