免费注册 查看新帖 |

Chinaunix

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

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

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-08 17:23 |只看该作者 |倒序浏览
大家好:
      我先给大家看段日志内容:
[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
       望高手捧场!谢谢!!!

论坛徽章:
0
2 [报告]
发表于 2008-09-08 17:40 |只看该作者
请高手助我一臂之力呀,谢谢啦!!

论坛徽章:
0
3 [报告]
发表于 2008-09-08 18:04 |只看该作者
awk '$1=="Sep" && $2 ==3 && $3>="19:55:39" && $3<="20:00:02"' /var/log/messages
高手已经搞出来了,呵呵

论坛徽章:
34
亥猪
日期:2015-03-20 13:55:11戌狗
日期:2015-03-20 13:57:01酉鸡
日期:2015-03-20 14:03:56未羊
日期:2015-03-20 14:18:30子鼠
日期:2015-03-20 14:20:14丑牛
日期:2015-03-20 14:20:31辰龙
日期:2015-03-20 14:35:34巳蛇
日期:2015-03-20 14:35:56操作系统版块每日发帖之星
日期:2015-11-06 06:20:00操作系统版块每日发帖之星
日期:2015-11-08 06:20:00操作系统版块每日发帖之星
日期:2015-11-19 06:20:00黄金圣斗士
日期:2015-11-24 10:43:13
4 [报告]
发表于 2008-09-08 18:11 |只看该作者
用 grep 也可以啊,grep "Sep  3 19:5[5~9]",awk 还得多练练~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP