我正在使用cPanel帐户,并具有一个Apache 2.4访问日志,该日志存储其日志,例如:
66.249.93.30 - - [04/May/2018:21:26:39 +0200] "GET / HTTP/1.1" 302 207 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Chrome/41.0.2272.118 Safari/537.36"
66.249.93.30 - - [05/May/2018:10:26:39 +0200] "GET / HTTP/1.1" 302 207 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Chrome/41.0.2272.118 Safari/537.36"
该日期的格式为日期“ +%d /%B /%Y:%k:%M:%S”
使用bash脚本,我只想提取最近一小时记录的行,例如:
完整的日志文件:
66.249.93.30 - - [04/May/2018:21:26:39 +0200] First Line
66.249.93.30 - - [05/May/2018:11:00:21 +0200] Second Line
66.249.93.30 - - [05/May/2018:11:15:39 +0200] Third Line
66.249.93.30 - - [05/May/2018:12:00:11 +0200] Fourth Line
当前时间: 05 / May / 2018:12 : 01:06
日志从: 5月5日11:01-12:01之间的时间间隔开始
过滤后的输出:
66.249.93.30 - - [05/May/2018:11:15:39 +0200] Third Line
66.249.93.30 - - [05/May/2018:12:00:11 +0200] Fourth Line
我已经尝试过使用awk和其他一些建议,但是我无法使其正常工作,我们将不胜感激!
RISEBY