首頁>Club>
2
回覆列表
  • 1 # 使用者6012801286615

    VBS指令碼壓縮IIS日誌

    緣起:今天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

  • 中秋節和大豐收的關聯?
  • 車子上坡如何正確換擋?