想处理apache生成的日志文件,每天按照一定规则提取日志放入当天的文件夹
代码:
- @echo off
- set year=%date:~0,4%
- set month=%date:~5,2%
- set day=%date:~8,2%
- set path=E:\log\%year%\%year%-%month%\%date:~2,2%-%month%-%day%
- if exist %path% (
- if exist %path%\ (
- exit
- ) else (
- ren "%path%" "%date:~2,2%-%month%-%day%-BAK"
- )
- )
- mkdir %path%
- for /f "delims=" %%a in ('type list.txt') do findstr "%%~a" test.log>>%path%\ %%a.log
- pause
复制代码
list.tet文件内容:
www.test1.com
www.test2.com
test.log文件内容:
202.105.58.83 - - [03/Sep/2018:03:18:05 +0800] "GET /zw/czzxzjglqd/ HTTP/1.1" 200 92679 "www.test1.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:05 +0800] "GET /zw/ztzl/ HTTP/1.1" 200 101731 "www.test1.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:11 +0800] "GET /zw/ztzl/jlshbdcjxs/ HTTP/1.1" 200 13349 "www.test1.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:11 +0800] "GET /zw/ztzl/2018cbszx/ HTTP/1.1" 200 15388 "www.test1.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:11 +0800] "GET /zw/ztzl/bsssthj/ HTTP/1.1" 200 93780 "www.test1.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:23 +0800] "GET /zw/ztzl/hbdc/ HTTP/1.1" 200 100183 "www.test2.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:29 +0800] "GET /zw/ztzl/bszpyc/ HTTP/1.1" 200 11582 "www.test2.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:29 +0800] "GET /sy/ztzl/yyssyd/ HTTP/1.1" 200 11242 "www.test2.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
202.105.58.83 - - [03/Sep/2018:03:18:29 +0800] "GET /zw/ggzyjy/ HTTP/1.1" 200 98161 "www.test2.com" "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
----------------------------------------------------------------分割线---------------------------------------------------------------------------------------------
①运行后出现错误,提示:'findstr' 不是内部或外部命令,也不是可运行的程序或批处理文件。for /f放在第二行就不会出现这个错误,应该是set path引起,但不知道怎么解决
②test.log并不是固定的文件,应该是access_Y%M%D%_log 按照日期每天生成的一个日志文件,这个地方该如何修改?
因为对批处理刚接触,很多东西搞不明白,请大神指教!小女子先谢过了! |