Solved

VB Script that will manage IIS http log files?

Posted on 2009-04-10
2
396 Views
Last Modified: 2012-05-06
I'm a greenhorn trying to work my way up to newbie status with examples of scripts on EE,
Ed Wilson's Windows Scripting Learning Guide, and Google.  

I want to copy the log files that are older than the current days date from the IIS server to a server we archive them on, and then delete the log file from the IIS server, both servers are in the same domain.  Or simply moving the files from one server to the other would work also.

We have thirty or so sites on the server, each site has a separate folder that contains that particular sites log files.  The structure looks like \\servername\web\logfiles\www.site.org\exyymmdd.log.

I'm asking for a script that would loop though the folder and either copies and deletes, or moves the log files.  I would use Task Manager to run the script once a week.

Thanks


Thanks


0
Comment
Question by:Westez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
Tompa99 earned 500 total points
ID: 24137322
Hi,

This vbscript is checking a folder and all sub folder for files named "*.log".
Then it will diff the date/time on DateLastModified attribute on the log file to get a date
to run a diff on. If that attribute is older then one day it will copy the file to a new folder.
The file will get the subfolder name below the main folder \\servername\web\logfiles and
then it's actual file name. "site1_20090414.log"

Alteast this script will get you started. There is no error handling in this script.

Regards Tompa
Dim objFSO
Dim FolderPath
Dim siteFolders
Dim CopyToFolder
FolderPath = "c:\logfiles" '\\servername\web\logfiles
CopyToFolder = "c:\temp\" 'Folder to copy to
 
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder (FolderPath)
 
for each subF in objFolder.SubFolders
	Set objSiteFolder = objFSO.GetFolder(FolderPath + "\" + subF.name) ' Getting the sub folders for each site
	for each file in objSiteFolder.Files
		fileTypeCheck = instr(ucase(file.Name), ".LOG")  'One verify that it is a log file  
		if filetypeCheck <> 0 then
			check = DiffADate(file.DateLastModified) ' Running Function DiffADate to find out Diffrence in date.
			if check <> 0 then ' if <> 0 then the file is older then one day and will be copied
				cmd = file.Copy(CopyToFolder + subF.name + "_" + file.Name,false) ' File will get the name subfoldername_20090414.log 
				runDelete = file.Delete ' Will delete the file after copy. No error handling in this script if copy goes wrong
			end if
		end if 
	next
next 
 
Function DiffADate(theDate)
   	DiffADate = DateDiff("d", Now, theDate) ' Now is the date and time when script is running
End Function

Open in new window

0
 

Author Closing Comment

by:Westez
ID: 31569058
Tompa99 thanks, this will get me started.  I've not had a chance to give it go, if something pops up I'll post another question.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBScript on Html 15 59
Need help Creating PowerShell Script 5 67
Need help Creating PowerShell Script 4 46
Write 1 row of data from Excel to a txt file 10 35
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question