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

全部博文(96)

文章存档

2009年(37)

2008年(59)

我的朋友

分类: 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
阅读(1206) | 评论(0) | 转发(0) |
0

上一篇:三国新语

下一篇:Kernel debugging with Kprobes

给主人留下些什么吧!~~