KWSupport

Kevin Weilbacher [SBS MVP] blog on SBS, WHS and other topics of interest!

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!

Posted: Dec 29 2007, 08:36 AM by kwsupport | with 7 comment(s)
Filed under: ,

Comments

Stevo said:

Using it now, super simple, logs under control, works great, thanks for the download

# January 17, 2008 2:47 PM

Bembeng Arifin said:

Hi, nice, simple and very useful script.

Thanks for the download too ;)

# February 24, 2008 11:25 PM

Jac said:

Hi, this works nicely for what I was looking for.

I used it on an internal ftp-server on which files are only allowed to stay for 7 days without removing the folder structure.

Thanks

# March 7, 2008 10:48 AM

Joe Allen said:

Holy Cow!  This thing works great!  Thanks for the download!

# March 10, 2008 2:57 PM

Earl said:

Works great but how do I have it delete the folders as well? Also is it possible to only delete/search folders that start with says backup*

# May 2, 2008 10:58 AM

Mini said:

this was excellent thanks for the help. Editing was a breeze

# June 4, 2008 3:07 PM

Norgy said:

Very neat and precise. awesome admin work and thanks for sharing

# October 8, 2008 5:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)