Chinaunix
标题:
nginx awk比较日志大小不对
[打印本页]
作者:
shawnloong
时间:
2017-05-13 15:14
标题:
nginx awk比较日志大小不对
nginx 日志格式
82.242.25.250 10.26.109.10 - - [13/May/2017:00:00:01 +0800] "POST /test/service/newCode.htm HTTP/1.0" 200 203 "-" "www.test.com" "10.26.198.200:41035" "0.057" "0.056" "-"
139.19.109.176 10.26.109.10 - - [13/May/2017:00:00:01 +0800] "POST /test/service/code.htm HTTP/1.0" 200 136 "-" "www.test.com" "18.26.114.106:41011" "0.098" "0.097" "Apache-HttpClient/4.3.1 (java 1.5)"
12.77.244.53 10.26.109.10 - - [13/May/2017:00:00:01 +0800] "POST /test/service/code.htm HTTP/1.0" 200 130 "-" "www.test.com" "17.26.114.106:41011" "0.070" "0.068" "Apache-HttpClient/4.3.6 (java 1.5)"
12.40.61.100 10.26.109.10 - - [13/May/2017:00:00:01 +0800] "POST /test/service/code.htm HTTP/1.0" 200 148 "-" "www.test.com" "1.26.112.158:41011" "0.059" "0.057" "Java/1.8.0_111"
12.26.72.175 10.26.109.10 - - [13/May/2017:00:00:01 +0800] "POST /test/service/code.htm HTTP/1.0" 200 148 "-" "www.test.com" "11.26.112.158:41011" "0.050" "0.049" "Java/1.8.0_101"
脚本内容
#!/bin/bash
nginx_log=/var/log/nginx/access.log
temp_log=/usr/scripts/10min.log
tac $nginx_log |
awk 'BEGIN{
# 获取时间至min20
"date -d \"-3000 minute\" +\"%H:%M:%S\"" | getline min10
}
{
if (substr($5,14) > min10)
print ;
else
exit;
}' |
tac>$temp_log
真实需求是获取10分钟内的日志,但是实际获取的是10秒内的日志
作者:
radish1027
时间:
2017-05-16 09:20
呃,我都是取到时间部分后转成Unix时间戳,再去用秒数获取范围
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2