免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1341 | 回复: 0
打印 上一主题 下一主题

关于日志检查脚本的一些构想 [复制链接]

论坛徽章:
4
ChinaUnix专家徽章
日期:2015-07-27 10:05:26IT运维版块每日发帖之星
日期:2015-09-01 06:20:00IT运维版块每日发帖之星
日期:2016-07-29 06:20:00PHP
日期:2016-10-25 16:08:01
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-24 17:18 |只看该作者 |倒序浏览
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 "
http://xxx.xxx.xxx/listen/alert.php?mid=1&host=xxx.xxx.xxx &msg
= ${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


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/88527/showart_2059342.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP