缘起:今天IIS网站服务器的一些应用,出现的莫名奇妙的错误。原来IIS日志把某个磁盘撑爆了。找了一些资料,用脚本把这个事情解决了。基本思路是:用VBS脚本枚举IIS所有站点,压缩需要处理的日志,删除压缩过的日志,然后放到任务计划中每天处理一次。现在放出代码:
rariislogclearlog.vbs
Dim objW3SVC
Set objW3SVC = GetObject(”IIS://localhost/W3SVC”)
Dim objFSO
Set objFSO = CreateObject(”Scripting.FileSystemObject”)
Dim objShell
Set objShell = CreateObject(”Wscript.Shell”)
For Each objSITE In objW3SVC
WScript.Echo(objSITE.Class)
If(objSITE.Class =”IIsWebServer”) Then
WScript.Echo(objSITE.LogFileDirectory&”\W3SVC”&objSITE.Name)
sFD = objSITE.LogFileDirectory&”\W3SVC”&objSITE.Name
If (objFSO.FolderExists(sFD)) Then
WScript.Echo(”文件夹存在”)
Set objFD = objFSO.GetFolder(sFD)
For Each oFl In objFD.Files
WScript.Echo oFl.Name
WScript.Echo oFl.Path
If Right(oFl.Name,4)=”.log” Then
WScript.Echo “ex”&Right(”00″&Year(Date()),2) &Right(”00″&Month(Date()),2)& Right(”00″&Day(Date()),2)
nametodate = “20″& Mid(oFl.Name,3,2)&”-”& Mid(oFl.Name,5,2)&”-”& Mid(oFl.Name,7,2)
WScript.Echo(nametodate)
WScript.Echo(DateDiff(”d”,nametodate,Date()))
WScript.Echo(DateDiff(”d”,”2009-08-01″,Date()))
If DateDiff(”d”,nametodate,Date()) > 0 Then
objShell.run “cmd /C “”C:\Program Files\WinRAR\WinRAR.EXE”" a “&sFD&”.rar “& oFl.Path,4,True
objFSO.DeleteFile(oFl.Path)
End If
End If
Next
End If
End If
Next