首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实时扫描文件并在遇到5行连续相同的行时执行某些命令

实时扫描文件并在遇到5行连续相同的行时执行某些命令
EN

Stack Overflow用户
提问于 2012-02-09 08:07:59
回答 1查看 243关注 0票数 0

Mysql日志有如下内容:

代码语言:javascript
复制
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1
1649560 Query select * from actions where uniqueid like 'ernie-1328697839.1233158-%-dequeue' and class='queue' and server='ernie' and time<='1328698322' and action='dequeue' limit 1

我想要一个bash脚本,它将执行如下操作:

脚本将实时扫描tail -F mysql.log)

  • If文件(类似于echo "yes")

,它遇到5行连续相同的行),然后调用一些命令(比如echo "yes"))

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-09 10:36:54

代码语言:javascript
复制
 awk '$0 != l { l=$0; c=0 }
      l=$0 {c++; if (c>=5) {system("YOURCOMMAND HERE")}}' LOGFILE

能为你做这件事。但你所说的实时是什么意思?如果必须不断地运行,请为其设置一些fifo机制,或者类似的机制。或者简单地做:

代码语言:javascript
复制
 tail -F LOGFILE | <THEABOVE_AWK_SCRIPT>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9207311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档