Get the App
SLTechnology News&Howtos  ›  Development  › 

How to count the IP visits of appche sites under linux

Shulou Source: shulou.com Published: 2022-06-01 04:00:09 09月22日 Update

This article introduces the relevant knowledge of "how to count IP visits to appche sites under linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

It is often necessary to count apache site visits according to ip addresses, the most basic script.

Sort in descending order according to the number of ip visits:

The copy code is as follows:

#! / bin/bash

# script_name: access_count

Acc_log=/usr/local/apache2/logs/access_log

/ bin/awk'{print $1}'$acc_log | sort | uniq-c | sort-nr

Execution effect:

The copy code is as follows:

[root@zabbix ~] # sh access_count

94989 192.168.100.34

38863 192.168.200.92

23658 192.168.1.71

16720 192.168.100.80

13688 192.168.200.34

1618 192.168.100.104

1251 192.168.1.202

1195 192.168.100.30

1058 192.168.1.203

934 192.168.1.208

792 127.0.0.1

773 192.168.5.126

189 192.168.1.68

Print the ip addresses of the top three visitors:

The copy code is as follows:

#! / bin/bash

# script_name:access_count

Acc_log=/usr/local/apache2/logs/access_log

/ bin/awk'{print $1}'$acc_log | sort | uniq-c | sort-nr | head-n 3

The copy code is as follows:

[root@zabbix ~] # sh access_count

94989 192.168.100.34

38863 192.168.200.92

23658 192.168.1.71

Apache site access error statistics:

The copy code is as follows:

#! / bin/bash

# script_name:error_count

Err_log=/usr/local/apache2/logs/error_log

Cat $err_log | grep-e "^\ [" | awk'{print $6}'| sort | uniq-c | sort-nr

The copy code is as follows:

[root@zabbix ~] # sh error_count

701 [core:notice]

30 [mpm_event:notice]

12 [core:warn]

1 [: error]

This is the end of the content of "how to count IP visits to appche sites under linux". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Code traffic site statistics content address more knowledge practicality achievement next dilemma reality situation effect article case editor website script Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker MariaDB Huawei Redmi