需要帮助查找“WAM1”和“WAM2”最近连续启动之间的时间差(仅秒)/var/log/messages
WAM1 是在推出的2013-07-09T02:20:10.735639Z
,2013-07-09T02:20:12.635639Z
所以现在 WAM2 的最新版本2013-07-09T02:20:12.635639Z
如此不同(15.84675 - 12.635639)= 3.211111
,结果以秒为单位
2013-07-09T02:20:10.735639Z user.info WbAppMg WAM1
2013-07-09T02:20:11.817372Z user.info sam SAM
2013-07-09T02:20:12.635639Z user.info WbAppMg WAM1
2013-07-09T02:20:13.817372Z user.info sam SAM
2013-07-09T02:20:14.818442Z user.info sam SAM
2013-07-09T02:20:15.846751Z user.info WbAppMg WAM2
2013-07-09T02:20:16.846636Z user.info sam SAM
2013-07-09T02:20:16.848751Z user.info WbAppMg WAM2
2013-07-09T02:20:17.851727Z user.info sam SAM
2013-07-09T02:20:18.935639Z user.info WbAppMg WAM1
2013-07-09T02:20:19.535639Z user.info WbAppMg WAM1
2013-07-09T02:20:20.817372Z user.info sam SAM
2013-07-09T02:20:21.818442Z user.info sam SAM
2013-07-09T02:20:22.746751Z user.info WbAppMg WAM2
2013-07-09T02:20:23.846636Z user.info sam SAM
2013-07-09T02:20:24.851727Z user.info sam SAM
下面的程序对上述日志消息给出了错误的结果
$ awk '
/WAM1/{ split($1,start,/[:Z]/); wam1[++i]=start[3] }
/WAM2/{ split($1,stop,/[:Z]/); wam2[++j]=stop[3] }
END { len=i>j?i:j; for(;x<len;)
print "Delta "++x" = "wam2[x]-wam1[x] }' /var/log/messages