Chinaunix首页 | 论坛 | 博客
  • 博客访问: 331013
  • 博文数量: 148
  • 博客积分: 2980
  • 博客等级: 少校
  • 技术积分: 2150
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-11 15:25
文章分类

全部博文(148)

文章存档

2010年(28)

2009年(62)

2008年(58)

我的朋友

分类: LINUX

2009-01-13 14:54:39

标  题: 用shell script 监控 logfile 应该怎样做?
发信站: 水木社区 (Tue Jan 13 10:03:48 2009), 站内

比如 tail -f /var/log/syslog 对输出做监控
发现有 AAA 出现 则做 taskA
发现有 BBB 则做 taskB


tail -f /var/log/messages | while read line
do
  A=`echo $line|grep AAA`
  B=`echo $line|grep BBB`
  if [ ${#A} -ne 0 ];
  then
     do_AAA_work
  fi
  if [ ${#B} -ne 0 ];
  then
     do_BBB_work
  fi
done


1. 做个named pipe
   mknod /tmp/a.pipe p
2. 在syslog.conf里面加一条
   *.* /tmp/a.pipe
   不一定要*.*,可以自定义
3. 读/tmp/a.pipe
   while read line ; do whatever done < /tmp/a.pipe
阅读(360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~