IIS log automatic cleanup

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.