IIS Log Auto-delete program favorites

Source: Internet
Author: User

Many webmasters who use Windows IIS may encounter this problem, that is, the server's IIS log growth often leads to full disk space, and IIS does not automatically delete the log, so you need to focus on the instant cleanup log, so I will introduce a program that can automatically delete IIS logs.

The function of this removal program is very simple, automatic daily deletion of the log n days ago (the time according to the circumstances of their own settings, generally set to 30 days), you can use DOS batch or VBS script to achieve.

In the solution below please you can choose to suit their own, the overall design idea is this:

The IIS log file format is: Ex month day. Log for example: Ex071116.log

IIS log files are stored in:%windir%\system32\logfiles, if you are using a professional IIS management software, it will generally let you set the appropriate log directory.

IIS Log Cleanup Batch version: According to the current time calculation of 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 months), and then processed into 20070916 such format, Then combine the IIS log file format into Ex070916.log so that we get the log file name to clean up then we'll use del/s/f D:\iislog\ex070916.log To clear the log in the folder directory and subdirectories of all the files of this file name, and thus 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 is scheduled to execute every day, so that all the computer log problems we can not control.

Adult must see the Sex science knowledge, a late sex education (next)

IIS Log cleanup VBS version: VBS version theory is not fast because of the IIS version, because he also with the help of script-driven, and unlike the CMD version of the DOS system directly using the batch processing function fast (guessed), VBS is a high-level language, the ability to process the date with a sentence to achieve, and CMD version to write half a page. The implementation of the IIS log Cleanup VBS version uses VBS to traverse all the files in the directory where the IIS logs are located, and then the file names are combined into the date type, and then the current date-this date, to see if it is more than the set number of days, the words Delete, One of the advantages of this idea is that you can clear all records from N days ago, not just one day, he can be your cmd version of the log cleanup, write this script to the scheduled task, run every day, or can be run manually once a period of time. This code is significantly less than the IIS log cleanup cmd version.

The IIS log cleanup cmd version code (DELIISLOG.BAT) code is as follows:

@echo offTitle:: Set how many days or days before the current dateset/a beforedays=-3:: Setting the location of your directorySet dir= "F:\log\":: The current date is converted to days and calculatedCall:D Ate2day%date:~0,10% daysset/a days=%days%%beforedays%Call:D ay2date%days% lastdate:: calculated to generate the desired character combinationSet Okstr=ex%lastdate:~2,6%.log:: Delete these filesDel del/f/s/q%dir%\%okstr%cmd/k:D Ate2daySetlocal enableextensionsfor/f "Tokens=1-3 delims=/-,"%%a in (' echo/%1 ') do (Set Yy=%%a & Set Mm=%%b & Set Dd=%%c)set/a dd=100%dd%%%100,mm=100%mm%%%100  set/a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2  set/a j=j/5+dd+y*365+y/4-y/100+y/400-2472633   Endlocal&set%2=%j%&goto:eof :D ay2date  setlocal enableextensions  set/a i=%1,a=i+ 2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a  set/a d=4*c+3,d/=1461, E=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5  set/a dd=-dd+e+1, Mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10  (if%mm% LSS set mm=0%mm%) & (If%dd% LSS set dd=0%dd%)   endlocal&set%2=%yy%%mm%%dd%& goto:eof

The IIS log cleanup VBS version code (DELIISLOG.VBS) code is as follows:

Adult must see the Sex science knowledge, a late sex education (ON)

' IIS log cleanup VBS version code (DELIISLOG.VBS)' Call Method: Deliislog ' IIS log path ', how many days of IIS logs are reserved' Traverse files under All files and subfolders under the IIS log folderFunction Deliislog (iislogpath,keepdays)On Error Resume NextSet oFSO = CreateObject ("Scripting.FileSystemObject")Set ofolder = Ofso.getfolder (Iislogpath)Set osubfolders = Ofolder.subfolders ' Get a collection of all folders in this directorySet ofiles = Ofolder.files ' Gets a collection of all the files in that directory' The first step is to process all files in the current directoryFor every ofile in Ofiles ' Traverse all Filesif Right (ofile.name,3) = "Log" then odate=cdate ("& Mid" (ofile.name,3,2) & "-" & Mid (ofile.name,5,2  ) & "-" & Mid (ofile.name,7,2)) if date-odate > Keepdays then Ofile.delete ' Determine if the IIS log file is to be processed, and if so, delete it directly End If next processes all directories under the current directory, making recursive calls to each osubfolder in osubfolders deliislog osubfolder.path,keep Days ' recursive Next End Function deliislog "D:\IISLogTest", 20 ' traversal

IIS Log Auto-delete program favorites

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.