Shell-Script

出現次數

  • January 17, 2019
184.13.80.102 - - [07/Jan/2019:00:33:10 -0500] "GET /?p=454 HTTP/1.1" 200 8822 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [07/Jan/2019:20:16:12 -0500] "GET /?p=454 HTTP/1.1" 200 8820 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0"
184.13.80.102 - - [07/Jan/2019:23:14:10 -0500] "GET /?p=454 HTTP/1.1" 200 8820 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:02:32:22 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:03:57:19 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:23:05:32 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:07:35:10 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:14:45:36 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:23:22:03 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [10/Jan/2019:23:50:28 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Linux i686; rv:60.0) Gecko/20100101 Firefox/60.0"
184.13.80.102 - - [13/Jan/2019:00:56:36 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [15/Jan/2019:20:47:56 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [15/Jan/2019:22:36:09 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"

該使用者試圖淹沒我的伺服器。如何使用catawk檢查access_log特定的ip並檢測ip嘗試訪問伺服器的天數?

在此範例中為 6 天。

您可以使用以下命令:

grep "$ip" log_file | cut -d '[' -f2 | cut -d '/' -f1 | uniq | wc -l

讓我們說ip addressto search 在變數ip中,並且log_file是您的日誌文件。

您可以將ip變數定義為ip="184.13.80.102".

#!/bin/bash
echo "enter the ip"
read ip
awk -v i="$i" '/i/{print $4}' filename| sed "s/\[//g"| awk '{print substr($1,1,2)}'|awk '{if (!seen[$1]++)print $1}'| wc -l| sed "1i Below are Number of times "$ip" exsists"

output
Below are Number of times 184.13.80.102 exsists
6

引用自:https://unix.stackexchange.com/questions/495092