Don't talk about anything. Go directlyCode
Import sqlite3 <br/> Import OS <br/> Import string <br/> Import fileinput <br/> path_log_nginx = R "e: /xxx-logs/20100904 "<br/> conn = sqlite3.connect ('Log. db') <br/> C = Conn. cursor () <br/> export c.exe cute ('''drop table log''') <br/> c.exe cute (''' create table log (IP text) ''') <br/> for file in OS. listdir (path_log_nginx): <br/> if not file. endswith (". log "): <br/> Print" Warn: % s is not a log file "% (File) <br/> continue <br/> Print" info: process file % s "% (File) <br/> for line in fileinput. input (OS. path. join (path_log_nginx, file): <br/> If line. startswith( "192.168. "): <br/> continue; <br/> c.exe cute (" insert into log (IP) values ('% s') "% (line [0: line. find ("--[")]) <br/> Conn. commit () <br/> export c.exe cute ("select IP, count (*) C from log group by IP having C> 1000 order by c desc ") <br/> # We can also close the cursor if we are done with it <br/> C. close () <br/> # <br/> Print "done... "<br/>
After completion
Sqlite3.exe log. DB
> Select IP, count (*) C from log group by IP having C> 1000 order by c desc;