IIS logs keep growing during running. If the IIS website is frequently called or improperly called, many logs are generated. I encountered a 20 GB system disk during system O & M. Due to program problems developed by the partner, the Web service was called every several hundred microseconds, which caused the log to expand to 8 ~ 9G. For servers with insufficient system disks or disk space. It is necessary to automatically clear IIS logs.
The script is as follows:
1. File Name: rmiislog. js
Script content:
Function dellogfile (beforedays)
{
VaR FSO = new activexobject ("scripting. FileSystemObject ");
VaR dir = FSO. getfolder ("C: \ WINDOWS \ system32 \ logfiles"); // change it to your IIS log directory.
For (VAR fc = new enumerator (dir. subfolders );! FC. atend (); FC. movenext ())
{
If (FC. Item (). Name. substr (0, 5) = "W3SVC ")
{
For (var logfiles = new Enumerator (fc. item (). Files );! Logfiles. atEnd (); logfiles. moveNext ())
{
Var fileName = logfiles. item (). name;
Var year = "20" + fileName. substr (2, 2 );
Var mouth = fileName. substr (4, 2 );
Var day = fileName. substr (6, 2 );
Var days = Math. round (new Date (). getTime ()-Date. UTC (year, mouth-1, day)/1000/60/60/24 );
If (days> = beforedays) logfiles. item (). Delete ();
}
}
}
}
Dellogfile (30); // delete logs 30 days ago
2. batch processing script
File Name: rmiislog. bat
Script content:
Cscript rmiislog. js
Configure a windows plan to regularly clean up logs.