Feed on
Posts
Comments

Windows tmpwatch

A lot of Windows services love to create log files (IIS for example), but when it comes to log rotation in Windows, the functionality is glaringly absent. In linux it’s as easy as “tmpwatch –mtime 24”. In Windows there actually is a solution, but it’s a bit more complicated.

For Windows 2000 you’ll need to download the ‘forfiles’ binary somewhere. Once you’ve got it, here’s the syntax:

-p = path
-m = search filter
-d = days older than X
-c = command to run
forfiles -pf:\ -m*.ctf -d-10 -c"CMD /c del @FILE : date >= 10 days"
forfiles -pg:\ -m*.ctf -d-10 -c"CMD /c del @FILE : date >= 10 days"

For Windows 2003 the command is included. The syntax is different, though:

/p = path
/s = recurse subdirectories
-m = search filter
-d = days older than X
-c = command to run
forfiles /p P:\Nexusds\xmlspool /s /m *.* /d -7 /c "cmd /c del @file"

For Windows 2008, reinstall. It’s about time you got familiar with linux.

Leave a Reply