KWSupport

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

Recent Posts

Tags

News

  • Check out the "Song of the Week" link!
    Xobni outlook add-in for your inbox

Community

Email Notifications

SBS Blogs

SBS2003 Links

Archives

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: Sat, Dec 29 2007 8:36 by kwsupport | with 16 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

Meera said:

The script is no longer available on the site. Could anyone please help??

# November 20, 2008 8:21 AM

kwsupport said:

Try again. I was updating my site.

# November 27, 2008 7:13 PM

kwsupport said:

Try again. I was updating my site.

# November 27, 2008 7:13 PM

Panos said:

sweet! thanks for the help!

# December 20, 2008 12:14 PM

Hari said:

You are simply great, very simple and easy to understand

# December 21, 2008 10:57 PM

Eamonn said:

Thanks. Works great for KiWi syslog Archive log clean up

# February 26, 2009 11:35 AM

Jose Antonio said:

Hi,

I don´t know what happend when I using \\server_name\share_folder, write in the log but don´t remove the files. When I use the Leter is working.

# March 30, 2009 10:42 AM

lary said:

This is a great script, But I also want to select and delete specific files like ".log and .duplicate" files only.

How can I modify the script to do so?

please help

# July 15, 2009 8:04 AM

Moses said:

Very clean and simple solution.

My (small) modification was to delete all files older than 30 days that weren't created on the 1st of a month, which I find useful for ETL logs where I may want to check the timings of a build from 18 months ago.

   if (file.datelastmodified < newdate then

became

   if (file.datelastmodified < newdate AND day(file.datelastmodified) <> 1) then

Thanks again,

Moses.

# July 27, 2009 12:02 AM