The shell script that statistics appche site IP traffic under Linux _linux

Source: Internet
Author: User

Often need to statistics Apache site traffic based on the IP address, the most basic script.

In descending order based on IP traffic:

Copy Code code as follows:

#!/bin/bash
#Script_name: Access_count

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

/bin/awk ' {print $} ' $ACC _log | Sort | uniq-c | Sort-nr

Execution effect:

Copy Code code 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

Top three IP addresses for print traffic:

Copy Code code as follows:

#!/bin/bash
#Script_name: Access_count

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

/bin/awk ' {print $} ' $ACC _log | Sort | uniq-c | Sort-nr | Head-n 3

Execution effect:

Copy Code code 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:

Copy Code code as follows:

#!/bin/bash
#Script_name: Error_count

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

Cat $err _log |  Grep-e "^\[" | awk ' {print $} ' | Sort | Uniq-c |SORT-NR

Execution effect:

Copy Code code as follows:

[Root@zabbix ~]# SH error_count
701 [Core:notice]
[Mpm_event:notice]
[Core:warn]
1 [: ERROR]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.