Recommended code to clean IIS logs in multiple scripts 1th/3 Page _ Other

Source: Internet
Author: User
Tags current time

Applications: Mainly used with virtual host, can also be used for personal server

Background: 2005 a month, the normal operation of the virtual host crashed, let the computer room on duty to restart a number of times, are not, the display into the system to see, tips: C disk space is insufficient, the middle of the night to go to the room to deal with, to the computer room after the first break network, and then into the system found two places have problems, C:\WINDOWS\ System32\logfiles file has 6G, there is a Symantec isolate the virus, to find the Internet, the greatest possibility is that all of our virtual host log is written here, and no one knows to write here, depressed, in the IIS looked at the next, is really such a thing, Log every day in the long, when the company orders a lot also no one to pay attention to this, then cleaned up a bit, the system is normal, back to the company after the IIS log changed to another disk.

Solution: But this is not the final Solution Ah, a virtual host hundreds of sites, and some sites can produce a day hundreds of m of log files, but also to clean up in time.
And there are two solutions:
1.60 days before the daily cleaning of the log
2. Over time, clean up the 60 days before the log.
But either way, it has to be handled by technology, manual to delete unless you are very professional, you can find 60 days before the log file to delete, but even if you are very good technology, this method is very time-consuming, the best way is: Using a DOS batch or script to implement, you can use the script is mainly VBS and JS.

There are several methods in the following solution that you can choose for yourself, and their overall design mentality is this:

The IIS log file is in the form of ex-month-day. Log, such as: Ex071116.log
IIS log file storage location:%windir%\system32\logfiles By default, if you are using a professional IIS management software, it will normally allow you to set up the appropriate log directory

IIS Log cleanup cmd version: According to the current time calculated the first n days of the date, such as today is: 2007-11-16, the first 60 days of the date is 2007-9-16 (the program can automatically identify 30 days or 31 days or run month), and then processed into 20070916 such a format, Then combine the IIS log file formats such as Ex070916.log so that we get the log file names to clean up and then we'll use del/s/f D:\iislog\ex070916.log To clear all files of this file name in the folder directory and subdirectories of the log. To clear the log, but this is only a day to clear the logs, so we have to add this batch to the scheduled task, so that it executes every day, so that all the computer log problems we can not control.

IIS Log cleanup VBS version: The VBS theory is that there is no IIS version fast, because he also need to use script-driven, and unlike the CMD version directly using the DOS System batch processing function quickly (guess), VBS is a high-level language, processing date ability with a word on the implementation, and the CMD version to write half a page. IIS log cleanup The implementation of the version of the VBS uses VBS to traverse all files and folders in the directory where the IIS logs reside, and then to combine the file names into the date type, and then the current date-this date to see if it is more than the set number of days, more than the words Delete, This idea has the advantage of being able to clear all the records of N days before, instead of just one day, he can you like the cmd version of the log cleanup, the script to write to the scheduled task, run every day, you can also run the time manually. This code is significantly less than the IIS log cleanup cmd version.

IIS Log Cleanup JS version: This version in fact, and IIS log clean up the VBS version is not much, the idea is the same, just use the scripting language is not the same, there is the call when the two parameters in each of the parameters: directory, this directory must be written: D:\\iislog, Used to use VBS as the main script, this is mainly to learn C #, I heard that both languages are similar, just also practice, also did not spend much time.

IIS Log Cleanup WSH version: WSH version is actually the simplest, because of his high degree of integration, the operating process is this: use VBS or JS to generate the file name to be processed, Then use the Wscript.Shell execution cmd command to handle, using the IIS log clean up the cmd version and IIS log clean up the VBS version of the advantages, this is only one day to process the log, of course, you can also change it to deal with many days of the log. Because of the high degree of WSH integration, you can do a lot of operations, so hackers are very fond of this, The most used is the Wscript.Shell, so the general security awareness of the higher server provider will be to disable this component, so that the best use of the function becomes the most can not be used, the least common.

Current 1/3 page 123 Next read the full text

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.