shell获取某个时间段的nginx日志内容
2022/9/14 5:17:34
本文主要是介绍shell获取某个时间段的nginx日志内容,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
从nginx日志中获取2014:04:01日 21:30至21:50的日志内容
cat web.log
192.168.16.105 - - [01/Apr/2014:21:26:21 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:28:22 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:31:36 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:42:14 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:45:22 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:46:32 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:46:54 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:47:03 +0800] "GET / HTTP/1.1" 502 172
192.168.16.105 - - [01/Apr/2014:21:48:31 +0800] "GET / HTTP/1.1" 200 26
192.168.16.105 - - [01/Apr/2014:21:50:08 +0800] "GET / HTTP/1.1" 200 26
192.168.16.105 - - [01/Apr/2014:21:51:21 +0800] "GET / HTTP/1.1" 200 26
192.168.16.105 - - [01/Apr/2014:21:52:48 +0800] "GET / HTTP/1.1" 200 26
方法1:sed
cat web.log | egrep "01/Apr/2014" | sed -n '/21:31:36/,/21:50:08/p'
方法二:awk
cat web.log | egrep "01/Apr/2014" | awk -F':' '$2 = 21 && $3 >= 30 && $3 <= 50'
注意:
1、sed中取的两个时间点21:31:36与21:50:08必须是日志中实际存在的,用21:30:01与21:50:01获取不到数据;
2、awk中$3小于等于50,包含了50:01-50:59的日志数据;
这篇关于shell获取某个时间段的nginx日志内容的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-13用Nginx防范DDoS攻击的那些事儿
- 2024-12-13用Terraform在AWS上搭建简单NGINX服务器指南
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享