我想出了下面的腳本,它列出了服務器日誌文件中需要超過10000000微秒(ServiceDuration在我們的日誌中記錄的值以微秒記錄的值)的呼叫,該文件存儲所有來到服務的呼叫。AWK意外的令牌錯誤
servicedurationlimit.awk
#!/bin/sh
dir1=$1/*.log
# for each log file in the input dir
for file1 in $dir1
do
echo $file1":"
awk '/#BeginLogEntry|ServiceDuration/ {
#get slow running service's information
if ($1 == "#BeginLogEntry")
{
split($0, a, "\t");
servinfo=a[3]" ServiceAt:"a[2];
} else {
getline;
if ($0 > 10000000)
{
print servinfo", ServDur:"$0
}
}
}' $file1
done
在運行該腳本,我得到以下錯誤:
./servicedurationlimit.awk /path/to/server/logs/
./servicedurationlimit.awk: line 12: syntax error near unexpected token `$0,'
./servicedurationlimit.awk: line 12: ` split($0, a, "\t"); '
能否請您幫助我理解這可能是導致此?
下面是示例的日誌文件(其2個日誌條目):
#BeginLogEntry 04.13 20:11:11.671 BROWSE_ALL
@Properties LocalData
IsJson=1
UserTimeZone=utc
@end
@IdcRSet AuditProps
2
auditPropertyKey
auditPropertyValue
ServiceDuration
62818
ServiceStartTime
{ts '2015-04-13 20:11:11.671'}
@end
#EndLogEntry 04.13 20:11:11.671 BROWSE_ALL
#BeginLogEntry 04.13 21:12:11.671 BROWSE_SOME
@Properties LocalData
IsJson=1
UserTimeZone=utc
@end
@IdcRSet AuditProps
2
auditPropertyKey
auditPropertyValue
ServiceDuration
162818123
ServiceStartTime
{ts '2015-04-13 21:12:11.671'}
@end
#EndLogEntry 04.13 21:12:11.671 BROWSE_SOME
下面是我在含有上述的日誌條目的日誌文件運行腳本後期望的輸出。
BROWSE_SOME ServiceAt:04.13 21:12:11.671, ServDur: 162818123
awk
版本信息
$ awk --version
GNU Awk 3.1.5
該輸出與給定示例日誌應該如何? – jkdba
@JohnK - 用期望的輸出更新了文章。 – vk239