linux under appche site IP statistics shell script
- 2020-05-09 19:47:12
- OfStack
It is often necessary to count the visits to the apache site by the IP address, the most basic script.
In descending order according to IP visits:
#!/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:
[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 address of the top 3 page views:
#!/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
Execution effect:
[root@zabbix ~]# sh access_count
94989 192.168.100.34
38863 192.168.200.92
23658 192.168.1.71
Statistics of access errors at apache site:
#!/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
Execution effect:
[root@zabbix ~]# sh error_count
701 [core:notice]
30 [mpm_event:notice]
12 [core:warn]
1 [:error]