免费注册 查看新帖 |

Chinaunix

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

SHELL提取日志的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-08 17:44 |只看该作者 |倒序浏览
大家好:
      我先给大家看段日志内容:
[root@localhost boot]# tail -n 20 /var/log/messages
Sep  3 19:52:06 localhost last message repeated 4 times
Sep  3 19:55:39 localhost last message repeated 4 times
Sep  3 19:57:06 localhost squid: Could not determine fully qualified hostname.  Please set 'visible_hostname'
Sep  3 19:57:50 localhost squid: Could not determine fully qualified hostname.  Please set 'visible_hostname'
Sep  3 19:59:53 localhost squid[30131]: Squid Parent: child process 30133 started
Sep  3 19:59:53 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:53 localhost squid[30131]: Squid Parent: child process 30133 exited due to signal 6
Sep  3 19:59:56 localhost squid[30131]: Squid Parent: child process 30135 started
Sep  3 19:59:56 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:56 localhost squid[30131]: Squid Parent: child process 30135 exited due to signal 6
Sep  3 19:59:59 localhost squid[30131]: Squid Parent: child process 30137 started
Sep  3 19:59:59 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:59 localhost squid[30131]: Squid Parent: child process 30137 exited due to signal 6
Sep  3 20:00:02 localhost squid[30131]: Squid Parent: child process 30158 started
Sep  3 20:00:03 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 20:00:03 localhost squid[30131]: Squid Parent: child process 30158 exited due to signal 6
Sep  3 20:00:04 localhost squid[30160]: Squid Parent: child process 30162 started
Sep  3 20:00:06 localhost squid[30131]: Squid Parent: child process 30166 started
Sep  3 20:00:06 localhost squid[30131]: Squid Parent: child process 30166 exited with status 1
Sep  3 20:00:06 localhost squid[30131]: Exiting due to repeated, frequent failures
       我想用SHELL实现的功能是:用SHELL提取固定时间内的的日志记录行,并进行输出,最好用AWK实现.例如:我想提取19:55:39至20:00:02这段时间的日志,那么脚本的输出就应该是:
Sep  3 19:55:39 localhost last message repeated 4 times
Sep  3 19:57:06 localhost squid: Could not determine fully qualified hostname.  Please set 'visible_hostname'
Sep  3 19:57:50 localhost squid: Could not determine fully qualified hostname.  Please set 'visible_hostname'
Sep  3 19:59:53 localhost squid[30131]: Squid Parent: child process 30133 started
Sep  3 19:59:53 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:53 localhost squid[30131]: Squid Parent: child process 30133 exited due to signal 6
Sep  3 19:59:56 localhost squid[30131]: Squid Parent: child process 30135 started
Sep  3 19:59:56 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:56 localhost squid[30131]: Squid Parent: child process 30135 exited due to signal 6
Sep  3 19:59:59 localhost squid[30131]: Squid Parent: child process 30137 started
Sep  3 19:59:59 localhost (squid): ipcache_init: DNS name lookup tests failed.
Sep  3 19:59:59 localhost squid[30131]: Squid Parent: child process 30137 exited due to signal 6
Sep  3 20:00:02 localhost squid[30131]: Squid Parent: child process 30158 started
       望高手捧场!谢谢!!!

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
2 [报告]
发表于 2008-09-08 17:51 |只看该作者
awk '$1=="Sep" && $2 ==3 && $3>="19:55:39" && $3<="20:00:02"' /var/log/messages

论坛徽章:
0
3 [报告]
发表于 2008-09-08 17:59 |只看该作者
NB,哈哈
谢谢大哥了!!

论坛徽章:
3
CU大牛徽章
日期:2013-03-13 15:29:07CU大牛徽章
日期:2013-03-13 15:29:49CU大牛徽章
日期:2013-03-13 15:30:19
4 [报告]
发表于 2008-09-08 18:45 |只看该作者
awk真不错。开始学awk
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP