WS_TJ.vbs
d = DateAdd("n", -6, Now()) strDate = Right(""&(100+Year(d)),2) & Right(""&(100+Month(d)),2) & Right(""&(100+Day(d)),2) 'strHr = Hour(time()) 'strMin = Minute(time()) 'starttime = timeserial(strHr, strMin - 10, 0) 'endtime = timeserial(strHr, strMin, 59) 'strHr = Right(""&(100+Hour(starttime)),2) logfilename = "ex" & strDate ' 当天日志文件名 logFilePath = "E:\Work\LogParser\LogFiles" ' IIS 日志目录 sqlPath = "E:\Work\LogParser\Work\WS_TJ_Insert.sql" ' 插入数据库脚本 checkPointPath = "E:\Work\LogParser\Work\Temp" ' 检查点,文件目录 server = "192.168.58.76" ' 服务器地址 dataBase = "MCMM" ' 数据库名 userName = "integration" ' 用户名 passWord = "123456" ' 密码 'Wscript.Echo starttime &":"& endtime &":"&logfilename FilesTree logFilePath ,logfilename '遍历 Function FilesTree(sPath, logfilename) '遍历一个文件夹下的所有文件夹文件夹 Dim fs, oFolder, oFiles, oSubFolders set fs = CreateObject("Scripting.FileSystemObject") Set oFso = CreateObject("Scripting.FileSystemObject") Set oFolder = oFso.GetFolder(sPath) Set oSubFolders = oFolder.SubFolders Set oFiles = oFolder.Files 'For Each oFile In oFiles 'WScript.Echo oFile.Path 'oFile.Delete 'Next Set WshShell = Wscript.CreateObject("Wscript.Shell") For Each oSubFolder In oSubFolders strCMD = "LogParser file:" & sqlPath & "?logPath=" & oSubFolder.Path & "+log=" & logfilename &_ " -iCheckPoint:" & checkPointPath & "\myCheckPoint_"& oSubFolder.name &".lpc -iw:ON -i:iisw3c -o:SQL -server:" & server & " -driver:""SQL Server"" -database:" & dataBase & " -username:" & userName & " -password:" & passWord & """" 'Wscript.Echo strCMD WshShell.run strCMD, 1, False 'oSubFolder.Delete 'FilesTree(oSubFolder.Path)'递归 Next Set oFolder = Nothing Set oSubFolders = Nothing Set oFso = Nothing End Function
WS_TJ_Insert.sql
/* View Code logparser file:tj_insert.sql?start=starttime+end=endtime+log=logfilename input parameter: start - starttime example:1:00:00 or 18:00:00 end - endtime example:1:09:59 or 18:59:59 log - logfilename example:ex10111601 or ex10111618 */ Select 'MCML','HANGZHOU',date, time, c-ip,cs-username,s-sitename,s-computername,s-ip,s-port,cs-method,cs-uri-stem,cs-uri-query,sc-status,sc-substatus,sc-win32-status,sc-bytes,cs-bytes,time-taken,cs-version,cs-host,cs(User-Agent),cs(Cookie),cs(Referer) INTO MCMM.dbo.MCML_WSLog_RawData FROM %logPath%\%log%.log