脚本在日志中grep模式

时间:2016-12-22 06:04:04

标签: bash perl shell

我想编写一个shell脚本或perl脚本来从日志中查找以下模式:

我从日志中查看的示例模式如下:

  

2016-11-21 04:46:30,491 http-threadID001 用户名286x64823x2 sessionID1 10.95.41.89,129.160.54.165,127.0.0.1 / rest / issueNav / 1 / issueTable JQL lucene查询:

     

2016-11-21 04:46:30,492 http-threadID001 用户名286x64823x2 sessionID1 10.95.41.89,129.160.54.165,127.0.0.1 / rest / issueNav / 1 / issueTable JQL排序:[<" custom:" customfield_10270" :com.atlassian.jira.issue.search.parameters.lucene.sort.DocumentSortComparatorSource@d6f17821&# 34;> ]

     

2016-11-21 04:46:30,492 http-threadID001 用户名286x64823x2 sessionID1 10.95.41.89,129.160.54.165,127.0.0.1 / rest / issueNav / 1 / issueTable Lucene布尔查询:

如果匹配模式相同的http-threadID001和相同的sessionID1,并且与issueTable JQL匹配:<" custom:" customfield_10270"并从日志中找到表Lucene布尔查询的问题,然后将电子邮件发送到support@blabla.com

此脚本将在unix crontask中设置,并且可能每1分钟运行一次。

有谁能告诉我如何编写这个脚本?谢谢!

1 个答案:

答案 0 :(得分:1)

 awk 'BEGIN{FS=" "}{print $0}' logfilename  |sed  -n '/http-threadID001/p; 
 /same sessionID1/p ; 
 / issueTable JQL sorts:/p; 
 /<"custom:"customfield_10270"/p; 
 /issue Table Lucene boolean Query/p'> file.tmp 

mailx -s "Subject" mailaddress <file.tmp
rm file.tmp

我希望这就是你需要的东西