Chinaunix首页 | 论坛 | 博客
  • 博客访问: 442349
  • 博文数量: 112
  • 博客积分: 4451
  • 博客等级: 上校
  • 技术积分: 1063
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-23 10:19
个人简介

更多精品http://shop65927331.taobao.com

文章分类

全部博文(112)

文章存档

2011年(19)

2010年(54)

2009年(39)

分类: LINUX

2011-04-12 09:22:35

If you are like me, you have to dig through some log files to research some errors.  The ../var/nagios.log file has alot of data and unfortunately the times stamps are not exactly friendly to read.

[1256314960] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;hostname;servicename;0;Service running OK

Using a little perl command line magic we can convert that ugly timestamp into something more readable.

[Fri Oct 23 11:22:40 2009] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;hostname;servicename;0;Service running OK

Just use...

perl -pe 's/(\d+)/localtime($1)/e' nagios.log

Of course that will spew the entire log.  So using grep or tail, you can make it a bit more useful.

perl -pe 's/(\d+)/localtime($1)/e' nagios.log |grep server1

tail nagios.log | perl -pe 's/(\d+)/localtime($1)/e'

注意,这条perl命令不会修改源文件,如果希望修改源文件,请先复制一份,然后 >>new file

原文链接:
阅读(1930) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~