grep awk sed 練習(xí)題

=====統(tǒng)計出18/Jun/2018的pv量======================================
[root@localhost nginx]# grep '18/Jun/2018:10:18:22' access.log |wc -l
6
=====統(tǒng)計出統(tǒng)計2018年6月18日一天內(nèi)訪問最多的2個IP(ip top10)======
[root@localhost nginx]# grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1]++ } END{ for( i in ips ) { print ips[i],i}}' |sort -k1 -rn |head -n2
34 192.168.44.1
6 192.168.44.47
=====統(tǒng)計出統(tǒng)計2018年6月18日一天內(nèi)訪問大于30的IP======
grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1]++ } END{ for( i in ips ) { if(ips[i]>30){print ips[i],i}}}' |sort -k1 -rn |head -n2
34 192.168.44.1

============統(tǒng)計出統(tǒng)計2018年6月18日一天ip對應(yīng)狀態(tài)碼的出現(xiàn)次數(shù)
[root@localhost nginx]# grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1" "$9]++ } END{ for(i in ips){ print i,ips[i]}}'|sort -k3 -rn
192.168.44.1 304 30
192.168.44.47 200 6
192.168.44.46 200 3
192.168.44.1 200 3
192.168.44.1 404 1
=====統(tǒng)計18/Jun/2018 8:30-9:00,訪問狀態(tài)碼是404 $9=="404"========
[root@localhost nginx]# awk '$4 >= "[18/Jun/2018:10:00:00" && $4 <= "[18/Jun/2018:11:00:00" { if($9=="404"){ips[$1" "$9]++} } END{ for (i in ips){ print i,ips[i]} }' access.log |sort -k3 -rn
192.168.44.47 404 2
192.168.44.46 404 2
192.168.44.1 404 1
=======查看nginx模塊================================
nginx -V 2>&1 |grep 'stub_s'
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容