The shell script implements the website log analysis statistics (can count 9 kinds of data) _linux shell

Source: Internet
Author: User

Wrote a shell script, can be used to count the daily access log, and sent to the e-mail to facilitate daily understanding of the site.
The script counts:
1, the total number of visits
2. Total Bandwidth
3. Independent Visitor Volume
4, access to IP statistics
5. Access URL Statistics
6. SOURCE Statistics
7, 404 statistics
8, search engine access statistics (Google, Baidu)
9, search engine source statistics (Google, Baidu)

Copy Code code as follows:

#!/bin/bash
Log_path=/home/www.jb51.net/log/access.log.1
Domain= "Jb51.net"
Email= "Log@jb51.net"
Maketime= ' Date +%y-%m-%d ' "%H": "%m"
Logdate= ' date-d ' Yesterday "+%y-%m-%d"
Total_visit= ' Wc-l ${log_path} | awk ' {print '} '
Total_bandwidth= ' Awk-v total=0 ' {total+=$10}end{print total/1024/1024} ' ${log_path} '
Total_unique= ' awk ' {ip[$1]++}end{print asort (IP)} ' ${log_path} '
ip_pv= ' awk ' {ip[$1]++}end{for (k in IP) {print ip[k],k}} ' ${log_path} | Sort-rn | Head-20 '
Url_num= ' awk ' {url[$7]++}end{for (k in URL) {print url[k],k}} ' ${log_path} | Sort-rn | Head-20 '
Referer= ' awk-v domain= $domain ' $11!~/http:\/\/[^/]* ' "$domain" '/{url[$11]++}end{for (k in URL) {print url[k],k}} ' ${log _path} | Sort-rn | Head-20 '
Notfound= ' awk ' $ = = 404 {url[$7]++}end{for (k in URL) {print url[k],k}} ' ${log_path} | Sort-rn | Head-20 '
Spider= ' awk-f ' "' $ ~/baiduspider/{spider[" Baiduspider "]++} $ ~/googlebot/{spider[" Googlebot "]++}end{for (k in SPID ER) {print k,spider[k]} ' ${log_path} '
Search= ' awk-f ' "' $ ~/http:\/\/www\.baidu\.com/{search[" Baidu_search "]++} $ ~/http:\/\/www\.google\.com/{search[ "Google_search"]++}end{for (k in search) {print k,search[k]} ' ${log_path} '
Echo-e "overview \ n report generation: ${maketime}\n Total Visits: ${total_visit}\n Total Bandwidth: ${total_bandwidth}m\n Independent Visitors: ${total_unique}\n\n Access IP Statistics \n$ {ip_pv}\n\n Access URL Statistics \n${url_num}\n\n source page Statistics \n${referer}\n\n404 statistics \n${notfound}\n\n spider statistics \n${spider}\n\n search engine source Statistics \n${ Search} "| Mail-s "$domain $logdate Log Statistics" ${email}

You need to modify the three variables log_path,domain and email, and then add this script to the scheduled task, you can receive the data of the statistics every day.

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.