1

"WAM1"以下のとの違いを見つける必要があり"WAM2"ます/var/log/messages

2013-07-09T02:20:18.535639Z user.info WbAppMg WAM1
2013-07-09T02:20:21.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  

以下のプログラムでは、いくつかのエラーが発生します

#!/bin/bash

file="/var/log/messages"
apploaded="WAM1"
appcreated="WAM2"
timepattern="{s/.*T[0-9]*:[0-9]*:\([0-9]*\.[0-9]*\)Z.*/\1/g;p}"
stop=`sed -n /$apploaded/$timepattern $file`
start=`sed -n /$appcreated/$timepattern $file`
delta=$(awk "BEGIN{print $stop-$start}")
echo Delta=$delta

のような出力

(WAM2-WAM1) = (22.746751-18.535639) = 4.211112 (Expected Output)
Delta== 4.211112
4

3 に答える 3