操作需要两个文件:blat.exe文件(用于发邮件),forfiles.exe文件(对日志文件进行处理)
1、
@echo off
net stop squid /y
rem pause wait...
For /F %%i In ('date /t') do ren f:\squid\log\access.log access%%i.log
For /F %%i In ("f:\squid\log") do copy f:\squid\log\access*.log f:\squid\bak\access*.log
For /F %%i In ("f:\squid\log") do del /q f:\squid\log\access*.log
type null > f:\squid\log\access.log
rem 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 dl-×××-01|IP 192.168.0.2|notify lzy821218@51cto.com |logfile f:\squid\log\access.log|comments squid log file|blat version "V3.1"
net start squid
2、
@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 dl-×××-01|IP 192.168.0.2|notify lzy821218@51cto.com |logfile f:\squid\log\access.log|comments squid log file|blat version "V3.1"
net start squid
:B
exit
3、
@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.18\i$\log file backup\EventLogs_%computername%_%a%_%b%_%HHMM%.cab" f:\squid\bak\access*.log
cabarc N "f:\squid\bak\EventLogs_%computername%_%a%_%b%_%HHMM%.cab" f:\squid\bak\access*.log
del /Q f:\squid\bak\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.2|notify lzy821218@51cto.com | logfile \\192.168.0.18\i$\log file backup\ |comments cabarc squid log file|blat version "V3.1"
4、
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 f:\squid\log /m access*.log -d -31 /c "cmd /c del /f @path"
rem cabarc N 新建一个打包文件
rem cabarc -m LZX:21 -r -p N "d:\bak\EventLogs_%computername%.cab" "D:\share\*.*"
5、BLAT文件的详细使用
注:先执行blat -install 邮件服务器IP 发件人地址
1、start blat.exe - -to lzy821218@51cto.com -base64 -charset Gb2312 -s "文件服务器备份已经完成" -body 声明: |%date%|%time%|computername dl-adv-02|IP 192.168.0.18|notify lzy821218@51cto.com |logfile i:\RobocopyLogs|comments file server backup|blat version "V3.1"
2、blat body.txt -to ***@tom.com -base64 -charset Gb2312 -subject "警告" -server smtp.***.com -u user -pw password
3、start blat.exe - -to lzy821218@51cto.com -s "Pingmon: Monitoring *.*.64.68 , initial state is -UP- at %date% %time%" -body "parms:| address *.*.64.68| frequency 2 | notify lzy821218@51cto.com | logfile i:\RobocopyLogs| comments publicDNS | version "V3.1"
4、start blat.exe - -to lzy821218@51cto.com -server 123.125.50.111 -u lzy821218 -pw printflzy -base64 -charset Gb2312 -s "文件服务器备份已经完成" -body 声明
转载于:https://blog.51cto.com/lzy821218/371372