|
Since this was the topic of an older thread, I figured that I would
share. I use the attached script (rename to a vbs extension) for moving files once every hour to a different partition, and at 2 a.m., the same script will zip up the proper files and leave a copy of the sniffer log unzipped so that it can be uploaded to them (a separate process handles this and then deletes that file). This was set up to recognize the file names that I use for IMail, JunkMail, Virus, Sniffer and ORF. More importantly, it includes a function that handles the renaming and then moving of each file, which can be cribbed from the script, and it has a loop and wait for error handling. Note that if you attempt to use the script as I have it (with customization of variables and removal of log types such as ORF), it uses WinZip's command line zipping which can be downloaded for free if you have a registered version of WinZip. One could substitute another command line zipping tool quite easily for this purpose. The beauty of this script is mostly that it understands the time stamps and can handle zipping the previous day's log file based simply on the present time stamp. Hopefully it is understandable and may be of use. Matt Colbeck, Andrew wrote: I agree, Darin. For the benefit of discussion, there is no "rename" method, just the move. So the rename should be very fast indeed when the source and target have the same path. I noted that there was no error checking, so a small loop there might be useful.Also, if someone really wanted to do a move, I would suggest tweaking the code to do a rename (move) in the current directory, then do a second move to the target directory. That will free up the active log file the quickest. Andrew 8) -----Original Message----- From: Darin Cox [mailto:[EMAIL PROTECTED]] Sent: Friday, December 10, 2004 6:50 AM To: [EMAIL PROTECTED] Subject: Re: [Declude.JunkMail] Moving logfiles out of spool Note that this is not copying...it's moving. So if it's on the same drive all it has to do is update the MFT, without actually copying the data. And between separate drives VBscript shouldn't be any slower than command line or other tools...it's the file copy itself that takes the time. Darin. ----- Original Message ----- From: "Markus Gufler" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, December 10, 2004 3:24 AM Subject: RE: [Declude.JunkMail] Moving logfiles out of spool Thanks for this example. I haven't tested it but I fear that for such large logfiles (4 x 100 - 250 MB) VBScript maybe is a little bit slow compareed to unixtools. I'll let you know if it will work. Markus-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Darin Cox Sent: Thursday, December 09, 2004 11:00 PM To: [EMAIL PROTECTED] Subject: Re: [Declude.JunkMail] Moving logfiles out of spool This is the VBS script I use. It's probably an chopped up version from someone else... ================================== Const OverwriteExisting = True Const SpoolPath = "F:\IMail\spool\" Const LogPath = "F:\IMail\spool\logarchive\" dim currdate, curryear, oldfile, newfile Set objFSO = CreateObject("Scripting.FileSystemObject") currdate= "" if month(now()-1)<10 then currdate=currdate & "0" & month(now()-1) else currdate=currdate & month(now()-1) end if if day(now()-1)<10 then currdate=currdate & "0" & day(now()-1) else currdate=currdate & day(now()-1) end if curryear = right(year(now()-1), 2) MoveLog "dec", "log", "" MoveLog "list", "txt", "" MoveLog "log", "txt", "" MoveLog "spam", "log", "" MoveLog "sys", "txt", "" MoveLog "vir", "log", "" MoveLog "W1", "log", curryear MoveLog "W2", "log", curryear Sub MoveLog(strType, strExt, strYear) oldfile = SpoolPath & strType & strYear & currdate & "." & strExt if objFSO.FileExists(oldfile) then objFSO.MoveFile oldfile, LogPath end if End Sub ================================== Darin. ----- Original Message ----- From: "Markus Gufler" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, December 09, 2004 4:40 PM Subject: [Declude.JunkMail] Moving logfiles out of spool Anyone can send me his script (cmdline, unixtools, perl, ...) that will move logfiles out of the spool folder to another partition on a daily or hourly basis? Thanks in advance Markus --- [This E-mail was scanned for viruses by Declude Virus (http://www.declude.com)] --- This E-mail came from the Declude.JunkMail mailing list. To unsubscribe, just send an E-mail to [EMAIL PROTECTED], and type "unsubscribe Declude.JunkMail". The archives can be found at http://www.mail-archive.com. --- [This E-mail was scanned for viruses by Declude Virus (http://www.declude.com)] --- This E-mail came from the Declude.JunkMail mailing list. To unsubscribe, just send an E-mail to [EMAIL PROTECTED], and type "unsubscribe Declude.JunkMail". The archives can be found at http://www.mail-archive.com.--- [This E-mail was scanned for viruses by Declude Virus (http://www.declude.com)] --- This E-mail came from the Declude.JunkMail mailing list. To unsubscribe, just send an E-mail to [EMAIL PROTECTED], and type "unsubscribe Declude.JunkMail". The archives can be found at http://www.mail-archive.com. --- [This E-mail was scanned for viruses by Declude Virus (http://www.declude.com)] --- This E-mail came from the Declude.JunkMail mailing list. To unsubscribe, just send an E-mail to [EMAIL PROTECTED], and type "unsubscribe Declude.JunkMail". The archives can be found at http://www.mail-archive.com. --- [This E-mail was scanned for viruses by Declude Virus (http://www.declude.com)] --- This E-mail came from the Declude.JunkMail mailing list. To unsubscribe, just send an E-mail to [EMAIL PROTECTED], and type "unsubscribe Declude.JunkMail". The archives can be found at http://www.mail-archive.com. -- ===================================================== MailPure custom filters for Declude JunkMail Pro. http://www.mailpure.com/software/ ===================================================== |
Dim fso
Dim sYY, sYYYY, sMM, sDD
Dim sIMailDir, sJunkMailDir, sVirusDir, sSnifferDir, sORFDir
Dim sIMailName, sJunkMailName, sVirusName, sSnifferName, sSnifferRename,
sORFName
Dim sIMailStamp, sJunkMailStamp, sVirusStamp, sSnifferStamp, sORFStamp
Dim sIMailExt, sJunkMailExt, sVirusExt, sSnifferExt, sORFExt
Dim sIMailDest, sJunkMailDest, sVirusDest, sSnifferDest, sORFDest
'---------------------------------------------------------------------------
' Generate Variables
'---------------------------------------------------------------------------
' Populate the Date strings
If DatePart("h", Now()) > 0 Then
sYY = Right(DatePart("yyyy", Now()), 2)
sYYYY = DatePart("yyyy", Now())
If DatePart("m", Now()) < 10 Then
sMM = "0" & DatePart("m", Now())
Else
sMM = DatePart("m", Now())
End If
If DatePart("d", Now()) < 10 Then
sDD = "0" & DatePart("d", Now())
Else
sDD = DatePart("d", Now())
End If
Else
sYY = Right(DatePart("yyyy", DateAdd("h", -1, Now())), 2)
sYYYY = DatePart("yyyy", DateAdd("h", -1, Now()))
If DatePart("m", DateAdd("h", -1, Now())) < 10 Then
sMM = "0" & DatePart("m", DateAdd("h", -1, Now()))
Else
sMM = DatePart("m", DateAdd("h", -1, Now()))
End If
If DatePart("d", DateAdd("h", -1, Now())) < 10 Then
sDD = "0" & DatePart("d", DateAdd("h", -1, Now()))
Else
sDD = DatePart("d", DateAdd("h", -1, Now()))
End If
End If
' Assign directories
sIMailDir = "F:\"
sJunkMailDir = "F:\"
sVirusDir = "F:\"
sSnifferDir = "C:\IMail\Declude\Sniffer\"
sORFDir = "F:\"
' Assign file name prefixes
sIMailName = "log"
sJunkMailName = "spam"
sVirusName = "virus"
sSnifferName = "your-sniffer-code"
sSnifferRename = "sniffer"
sORFName = "orf"
' Assign file name stamps
sIMailStamp = sMM & sDD
sJunkMailStamp = sMM & sDD
sVirusStamp = sMM & sDD
sSnifferStamp = sMM & sDD
sORFStamp = sMM & sDD
' Assign extensions
sIMailExt = ".txt"
sJunkMailExt = ".log"
sVirusExt = ".log"
sSnifferExt = ".log"
sORFExt = ".log"
' Assign destination directories
sIMailDest = "W:\IMail\"
sJunkMailDest = "W:\Spam\"
sVirusDest = "W:\Virus\"
sSnifferDest = "W:\Sniffer\"
sORFDest = "W:\ORF\"
'---------------------------------------------------------------------------
' Main Script
'---------------------------------------------------------------------------
'Create the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Rename to temporary and combine files with those in the destination folder,
or just move them if current file does not exist
Call CombineOrMove(sIMailDir & sIMailName & sImailStamp & sIMailExt,
sIMailDest, sIMailName & sImailStamp & sIMailExt)
Call CombineOrMove(sJunkMailDir & sJunkMailName & sJunkMailStamp &
sJunkMailExt, sJunkMailDest, sJunkMailName & sJunkMailStamp & sJunkMailExt)
Call CombineOrMove(sVirusDir & sVirusName & sVirusStamp & sVirusExt,
sVirusDest, sVirusName & sVirusStamp & sVirusExt)
Call CombineOrMove(sSnifferDir & sSnifferName & sSnifferExt, sSnifferDest,
sSnifferRename & sSnifferStamp & sSnifferExt)
' At midnight, move the ORF log to archive and copy a version of the Sniffer
log file for uploading
If DatePart("h", Now()) = 0 Then
fso.CopyFile sSnifferDest & sSnifferRename & sSnifferStamp &
sSnifferExt, sSnifferDest & "hb064pkq.log"
fso.MoveFile sORFDir & sORFName & sORFStamp & sORFExt, sORFDest &
sORFName & sORFStamp & sORFExt
End If
' Zip up files at 2 a.m.
If DatePart("h", Now()) = 2 Then
sYY = Right(DatePart("yyyy", DateAdd("h", -3, Now())), 2)
sYYYY = DatePart("yyyy", DateAdd("h", -3, Now()))
If DatePart("m", DateAdd("h", -3, Now())) < 10 Then
sMM = "0" & DatePart("m", DateAdd("h", -3, Now()))
Else
sMM = DatePart("m", DateAdd("h", -3, Now()))
End If
If DatePart("d", DateAdd("h", -3, Now())) < 10 Then
sDD = "0" & DatePart("d", DateAdd("h", -3, Now()))
Else
sDD = DatePart("d", DateAdd("h", -3, Now()))
End If
sIMailStamp = sMM & sDD
sJunkMailStamp = sMM & sDD
sVirusStamp = sMM & sDD
sSnifferStamp = sMM & sDD
sORFStamp = sMM & sDD
wscript.echo(sIMailStamp)
Call DoZip(sIMailDest, sIMailName & sImailStamp, sIMailExt)
Call DoZip(sJunkMailDest, sJunkMailName & sJunkMailStamp, sJunkMailExt)
Call DoZip(sVirusDest, sVirusName & sVirusStamp, sVirusExt)
Call DoZip(sSnifferDest, sSnifferRename & sSnifferStamp, sSnifferExt)
Call DoZip(sORFDest, sORFName & sORFStamp, sORFExt)
End If
'Destroy the FileSystemObject
Set fso = Nothing
'---------------------------------------------------------------------------
' Sub: CombineOrMove
' Contents: Moves a file to a temporary directory
' Arguments: Source file, destination directory, destination file name
' Returns: No value
'---------------------------------------------------------------------------
Sub CombineOrMove(ByVal sSource, ByVal sDestinationDir, ByVal sDestinationFile)
Dim oFileName
Dim oSource
Dim oDestination
' Disable error handling
On Error Resume Next
' Rename the specified file, retry after 5 seconds if error is found, limit to
30 tries.
intRetry = 30
Do While intRetry > 0
Set oFileName = fso.GetFile(sSource)
oFileName.Name = Right(sSource, Len(sSource) - InstrRev(sSource, "\",
-1, 1)) & "-temp"
If Err <> 0 Then
WScript.Sleep 5000
Err.Clear
intRetry = intRetry - 1
Else
intRetry = -1
End If
Loop
' Quit the script if it has retried the rename operation 30 times
If intRetry = 0 Then
WScript.Quit(0)
End If
' Re-enable error handling and close the oFileName object
On Error GoTo 0
Set oFileName = Nothing
' Combine or move the contents
If (fso.FileExists(sDestinationDir & sDestinationFile)) Then
Set oSource = fso.OpenTextFile(sSource & "-temp", 1, False)
Set oDestination = fso.OpenTextFile(sDestinationDir & sDestinationFile,
8, True)
Do While Not oSource.AtEndOfStream
oDestination.WriteLine oSource.ReadLine
Loop
oSource.Close
oDestination.Close
Else
fso.MoveFile sSource & "-temp", sDestinationDir & sDestinationFile
End If
End Sub
'---------------------------------------------------------------------------
' Sub: DoZip
' Contents: Moves a file to a temporary directory
' Arguments: Directory, file name, file extension
' Returns: No value
'---------------------------------------------------------------------------
Sub DoZip(ByVal sDirectory, ByVal sFileName, ByVal sExtension)
set shell = WScript.CreateObject("WScript.Shell")
shell.run "C:\Progra~1\WinZip\wzzip -m -ybc " & sDirectory & sFileName & ".zip
" & sDirectory & sFileName & sExtension
Set shell = Nothing
End Sub
