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.