kookers Posted May 24, 2012 Share Posted May 24, 2012 I have been working on this script that creates a zip file by month and moves the proper log files to that specific zip file, then delete the log files and send an email What I'd like it to do now is have the ability to tell the script, zip files x days old and add tracking information on the email that is being sent to include all log files that have been moved to a specific zip file. Hopefully someone can assist.Version:0.9 StartHTML:00000107 EndHTML:00019141 EndFragment:00019101 EndFragment:00000000 '============================================================================= ' Scheduled Task - Visual Basic ActiveX Script '============================================================================= ' Date : 05/31/2012' Auth : Kookers' Desc : VBScript file that Zips log files by Month and Year' Opt : '============================================================================= strRoot = "C:\WINDOWS\system32\LogFiles\MSFTPSVC1"strExt = "log"strServer = "SERVER_NAME"blnDeleteOriginals = TrueNumberOfDays = 15 'Anything older than this many days will be archived and deleted'Constants / VariablesConst EmailFrom = "LogFileCleanup@MyDomain.com"Const EmailTo = "kookers@MyDomain.com"Dim CurrentDateDim MsgDim fsCurrentDate = NowSet fs = CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject")Set objRoot = objFSO.GetFolder(strRoot)Set objEmail = CreateObject("CDO.Message")For Each objFile In objRoot.Files strFile = objFile.Path strFileExt = objFSO.GetExtensionName(strFile) If LCase(strFileExt) = LCase(strExt) Then dtmFile = objFile.DateLastModified strZIP = strRoot & "\" & Year (dtmFile) &_ MonthName(Month(dtmFile)) & ".zip" ZipFile strFile, strZip 'If blnDeleteOriginals Then If blnDeleteOriginals AND DateDiff("d",objFile.DateCreated,Date) > 0 Then objFile.Delete True End If End IfNext Sub ZipFile(strFileToZip, strArchive) Set objFSO = CreateObject("Scripting.FileSystemObject") If Not objFSO.FileExists(strArchive) Then Set objTxt = objFSO.CreateTextFile(strArchive) objTxt.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0)) objTxt.Close End If WScript.Sleep 2000 Set objApp = CreateObject("Shell.Application") intCount = objApp.NameSpace(strArchive).Items.Count + 1 objApp.NameSpace(strArchive).CopyHere strFileToZip Do WScript.Sleep 200 Set objNameSpace = objApp.NameSpace(strArchive) If Not objNameSpace Is Nothing Then If objNameSpace.Items.Count = intCount Then Exit Do End If End If LoopEnd Sub objEmail.From = EmailFromobjEmail.To = EmailToobjEmail.Subject = "Log File Complete on Server"'objEmail.Textbody = "Log Files for %Server% have been Zipped and deleted from server"'objEmail.TextBody = "Log File original path"(strRoot)objEmail.TextBody = "The monthly scheduled task to remove logs on" & "strServer" & "older than 30 days has completed." & vbCrLf & vbCrLf & "Deleted " & intFiles & " File(s) on " & strPath2Logs & vbCrLf & _ vbCrLf & "FILES:" & vbCrLf & "===================" & vbCrLf & strFilesobjEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ExchangeServerName.MyDomain.com"objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25objEmail.Configuration.Fields.UpdateobjEmail.Send Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.