假设Nginx的日志存储在nowcoder.txt里,内容如下: 192.168.1.20 - - [21Apr2020:14:12:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.21 - - [21Apr2020:15:00:49 +0800] "GET 2index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [21Apr2020:21:21:49 +0800] "GET 3index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.23 - - [21Apr2020:22:10:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.24 - - [22Apr2020:15:00:49 +0800] "GET 2index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.25 - - [22Apr2020:15:26:49 +0800] "GET 3index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.20 - - [23Apr2020:08:05:49 +0800] "GET 2index.php HTTP1.1" 404 490 "-" "Baiduspider" 192.168.1.21 - - [23Apr2020:09:20:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [23Apr2020:10:27:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [23Apr2020:10:27:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.20 - - [23Apr2020:14:12:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.21 - - [23Apr2020:15:00:49 +0800] "GET 2index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [23Apr2020:15:00:49 +0800] "GET 3index.php HTTP1.1" 404 490 "-" "Baiduspider" 192.168.1.25 - - [23Apr2020:16:15:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.24 - - [23Apr2020:20:27:49 +0800] "GET 2index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.25 - - [23Apr2020:20:27:49 +0800] "GET 3index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.20 - - [23Apr2020:20:27:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.21 - - [23Apr2020:20:27:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [23Apr2020:20:27:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.22 - - [23Apr2020:22:10:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 192.168.1.21 - - [23Apr2020:23:59:49 +0800] "GET 1index.php HTTP1.1" 404 490 "-" "Mozilla5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko20100101 Firefox45.0" 现在需要编写Shell脚本统计每分钟的请求数,并且按照请求数降序排序。你的脚本应该输出: 5 20:27 4 15:00 2 22:10 2 14:12 2 10:27 1 23:59 1 21:21 1 16:15 1 15:26 1 09:20 1 08:05
输入描述:
1
输出描述:
1
示例1
输入
192.168.1.20 - - [21/Apr/2020:14:12:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [21/Apr/2020:15:00:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [21/Apr/2020:21:21:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.23 - - [21/Apr/2020:22:10:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [22/Apr/2020:15:00:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [22/Apr/2020:15:26:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:08:05:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Baiduspider"
192.168.1.21 - - [23/Apr/2020:09:20:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:14:12:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:15:00:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:15:00:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Baiduspider"
192.168.1.25 - - [23/Apr/2020:16:15:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [23/Apr/2020:20:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [23/Apr/2020:20:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:22:10:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:23:59:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
输出
5 20:27
4 15:00
2 22:10
2 14:12
2 10:27
1 23:59
1 21:21
1 16:15
1 15:26
1 09:20
1 08:05
加载中...