腳本須要blat.exe、 forfile.exe文件,將這兩個文件放入到%systemroot%\system32目錄下!服務器
一、日記文件打包後刪除腳本.batide
@echo off
FOR /F "eol=; tokens=1,2 delims= " %%i in ('DATE /T') Do SET a=%%i
FOR /F "eol=; tokens=1,2 delims= " %%i in ('DATE /T') Do SET b=%%j
FOR /F "eol=; tokens=1,2 delims=: " %%i in ('TIME /T') Do Set HHMM=%%i%%j
cabarc N "\\192.168.0.1\f$\I\log file backup\EventLogs_%computername%_%a%_%b%_%HHMM%.cab" "e:\squid\bak\access*.log"
cabarc N "e:\squid\bak\EventLogs_%computername%_%a%_%b%_%HHMM%.cab" "e:\squid\bak\access*.log"
del /Q e:\squid\bak\access*.log
forfiles /p E:\squid\bak /m EventLogs*.cab -d -31 /c "cmd /c del /f @path"
start blat.exe - -to lzy821218@51cto.com -base64 -charset Gb2312 -s "代理服務器日誌打包已完成!" -base64 -charset Gb2312 -body "聲明: |%date%|%time%|computername test-01|IP 192.168.0.1|notify lzy821218@sina.com|logfile \\192.168.0.1\f$\I\log file backup\ |comments cabarc squid log file|blat version "V3.1"ui
rem FOR /F "eol=; tokens=1,2* delims= " %%i in ('DATE /T') Do SET a=%%i
rem FOR /F "eol=; tokens=1,2 delims= " %%i in ('DATE /T') Do SET b=%%j
rem {eol=;} 忽略分號
rem {delims= } 以空格做爲分割符
rem {tokens=1,2} 提取分割後的1和2的內容代理
rem forfiles /p e:\squid\log /m access*.log -d -31 /c "cmd /c del /f @path"日誌
rem cabarc N 新建一個打包文件token
rem cabarc -m LZX:21 -r -p N "d:\bak\EventLogs_%computername%.cab" "D:\share\*.*"rem
二、代理服務器日誌文件處理(計算文件大小).batcmd
@echo off
for %%1 in ("f:\squid\log\access.log")do if %%~z1 geq 5242880 goto A
for %%2 in ("f:\squid\log\access.log")do if %%~z2 lss 5242880 goto B
:A
net stop squid /y
rem pause wait...
For /F %%i In ('date /t') do ren f:\squid\log\access.log access%%i.log
forfiles /p f:\squid\log /m access*.log -d -31 /c "cmd /c del /f @path"
type null > f:\squid\log\access.log
ram copy nul f:\squid\log\access.log
start blat.exe - -to lzy821218@51cto.com -base64 -charset Gb2312 -s "代理服務器操做已完成!" -base64 -charset Gb2312 -body "聲明: |%date%|%time%|computername test-01|IP 192.168.0.1|notify lzy821218@sina.com|logfile f:\squid\log\access.log|comments squid log file|blat version "V3.1"
net start squid
:B
exitit
三、squidlog-oneday.batio
@echo off net stop squid /y rem pause wait... For /F %%i In ('date /t') do ren e:\squid\log\access.log access%%i.log For /F %%i In ("e:\squid\log") do copy e:\squid\log\access*.log e:\squid\bak\access*.log For /F %%i In ("e:\squid\log") do del /q e:\squid\log\access*.log type null > e:\squid\log\access.log rem copy nul e:\squid\log\access.log start blat.exe - -to lzy821218@51cto.com -base64 -charset Gb2312 -s "代理服務器操做已完成!" -base64 -charset Gb2312 -body "聲明: |%date%|%time%|computername dl-×××-01|IP 192.168.0.1|notify lzy821218@sina.com|logfile f:\squid\log\access.log|comments squid log file|blat version "V3.1" net start squid