Cleanup Old Log Files (revisited)
Back in Nov-2006 I wrote about a free script (WaRmZip) you could download to be used for deleting old log files. That script includes a lot of features and flexibility.
Here's a simpler script that does a similar cleanup of old log files that you might find useful. It includes a .vbs backend script plus a simple one line .bat batch file script that can be added to your SBS scheduler.
1. You can download a zip file from my website that contains the .vbs file, a sample .bat file and a sample log file. To keep things simply, I store these files on my SBS server's in a C:\scripts folder.
2. The .vbs file does not need any editing at all. It is designed to search, starting at a specified folder, plus all sub folders below it. Howerver, if you wish to play it safe while testing, you can edit the .vbs file and remark out the file.delete line located on line 37 near the end of the script.
3. The .bat file will define the starting folder and the age of files to be deleted, and will create a log file so you can track the files deleted. This batch file can then be scheduled to run daily, weekly or whatever. You can either create separate batch files or just add additional cscript lines to this one batch file.
Here's an example of the batch file IU use to cleanup IIS log files over 30 days old:
cscript c:\scripts\deloldfiles.vbs c:\windows\system32\logfiles 30 >> c:\scripts\iis.log
And here is part of the corresponding log file it creates:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Today:12/29/2007 8:32:06 AM
Started deleting files older than :11/29/2007 8:32:06 AM
________________________________________________
Deleting Files under the Folder:C:\WINDOWS\system32\LogFiles
__________________________________________________________________________
Deleting C:\WINDOWS\system32\LogFiles\IN071105.log last modified: 11/5/2007 7:18:34 PM
Deleting C:\WINDOWS\system32\LogFiles\IN071110.log last modified: 11/10/2007 3:47:43 PM
Deleting C:\WINDOWS\system32\LogFiles\IN071118.log last modified: 11/18/2007 11:55:00 AM
Deleting C:\WINDOWS\system32\LogFiles\IN071123.log last modified: 11/23/2007 11:43:26 PM
__________________________________________________________________________
Completed deleting files older than :11/29/2007 8:32:06 AM
________________________________________________
Enjoy!