Login | |
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/18/2006 11:52:36 PM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
if this were me, with 15 servers to run this on, i would switch to a more centralized script and run it from one machine eg. search via wmi for the file get the files over a file share (\\server\file) process them keep all the logs locally on the server the script runs on
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/19/2006 12:01:12 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
well my general rule of thumb is this (for servers or workstations) if i have to run the same script on two or more machines i generally try to centralize it for easier control and maintenance (wait til you find a bug and have to redeploy the script back out to 15 servers, or check the logs on each of them and youll see what im talking about ;)) the only caveat that i can think of is that you may not have the full functionality you need and wmi is notoriously slow... on that note, i am going back to bed ill check back when i get back up
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/19/2006 12:38:11 AM
|
|
 |
|
| |
swerver
Posts: 27
Score: 0
Joined: 12/18/2006
Status: offline
|
quote:
ORIGINAL: ehvbs I don't want to insist; let's use dates. But what about missing a whole day's files because the script didn't run (successfully) on server 11 last sunday? Get all relevant info about current file Get name, split into interesssing parts (file.Name, .Path, RegExp?) Get date (create, written, accessed?), split into interesting parts (Month,..., or RegExp) combine info intellegently (?) to determine action your move, swerver! Hi, how else would I handle the process if not using the Date function? How would it work on for the previous day without calling the date? The key attribute are the filename and the date modified. The files we are concerned with are MSDE logs on an ISA Server. The way Microsoft have set these up is that they have to be converetd to text inorder to read them and this conversion has to be done on an ISA as far as I am aware i.e. they are locked down so that only the ISA can modify them.
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/19/2006 3:03:57 AM
|
|
 |
|
| |
swerver
Posts: 27
Score: 0
Joined: 12/18/2006
Status: offline
|
Option Explicit Dim DateToCheck 'Date - This will be calculated as the day before the script is run Dim FilenameRegExp 'String - A regular expression to find all files containing the previous day's date Dim CheckYear 'Integer - The year component of the previous day's date Dim CheckMonth 'Integer - The month component of the previous day's date Dim CheckDate 'Integer - The day component of the previous day's date Dim objFSO 'File System Object Dim objFolder 'Folder Object Dim inputFolder 'String - Folder/Directory containing the log files you need processing Dim outputFolder 'String - Folder/Directory where you want the output to go Dim colFiles 'Object representing list of files Dim objFile 'Object representing a single file Dim objShell 'Object representing a shell access Dim objExecObject 'Onject represneting an external process Dim tempFileName 'String - temporary file name used to identify files that were created yesterday Dim fileNameLength 'Int - the length of the file name being checked Dim fileNumber 'Int - the number attached at the end of the filename eg. 001 from ISALOG_20061101_WEB_001.MDF Dim inputFileName 'String - the filename to pass to the other vbscript Dim outputFileName 'String - the filename to output the file to. inputFolder = "D:\test" 'change as required outputFolder = "D:\test\processed" DateToCheck = DateAdd("d",-1,Date) CheckYear = DatePart("yyyy" , DateToCheck) CheckMonth = DatePart("m" , DateToCheck) CheckDate = DatePart("d" , DateToCheck) 'Set the filename(s) to Search for tempFileName = "ISALOG_" & CheckYear & CheckMonth & CheckDate Set objFSO = CreateObject("Scripting.FileSystemObject") Wscript.Echo "Checking status of directory " & inputFolder If objFSO.FolderExists(inputFolder) Then Set objFolder = objFSO.GetFolder(inputFolder) Else Wscript.Echo "Folder does not exist" End If Set colFiles = objFolder.Files Wscript.Echo "Checking for log files from " & DateToCheck For Each objFile in colFiles if InStr (objFile.Name, tempFileName) > 0 Then Wscript.Echo "Processing " & objFile.Name fileNameLength = Len(objFile.Name) 'Generate the ISALOG_20061101_WEB_000 part of the filename inputFileName = Left(objFile.Name, fileNameLength - 4) 'Change the 22 in the following line to 21, and the 2 to 3 if you need to expand from _01, 02 to _001, 002 filenames fileNumber = Mid(objFile.Name,22,2) if fileNumber = "00" Then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & ".txt" else outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & fileNumber & ".txt" End if Wscript.Echo "msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName 'Uncomment the lines below, and this SHOULD run as intended. 'Set objShell = WScript.CreateObject("WScript.Shell") 'Set objExecObject = objShell.Exec(""msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName") End If Next
< Message edited by swerver -- 12/20/2006 1:11:08 AM >
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/19/2006 6:57:27 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
ok back, i feel a lil better now so can focus better ;) regarding the date, that's fairly simple to get yesterday's date date() - 1 however I noticed that you have a specific format that you need so we will have to use/modify an existing function that I use you can use your date setup until you get to a date that only has one digit (like next month) and you will lose your zero... ISALOG_20061101_WEB_000 this should work prevDate = Year(Now()) & Right("0" & Month(now()), 2) & Right("00" & Day(Now() - 1), 2) to mount a share from another server... Sub mapShare(yn,server,share) 'local drive to mount to drive = "B:" Set WshNetwork = WScript.CreateObject("WScript.Network") If yn = "y" Then WshNetwork.MapNetworkDrive drive, "\\" & server & "\" & share WScript.Echo "Share mounted On " & drive & " from " & server & " With remote path " & share Else WSHNetwork.RemoveNetworkDrive drive WScript.Echo "Share unmounted from " & server End If Set WshNetwork = Nothing End Sub 'mapShare now, having said all that, here is how i would create the flow (pseudo code follows) servers = array("server1","server2", ...) 'until you get all 15 create FSO stuff here for each server in servers 'mount share mountshare "y",server,"c$\path\to\files" if fso.fileexists(filename) 'process files end if mountshare "n",server,"" next how bout that...
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/20/2006 2:43:34 AM
|
|
 |
|
| |
swerver
Posts: 27
Score: 0
Joined: 12/18/2006
Status: offline
|
Option Explicit Dim DateToCheck 'Date - This will be calculated as the day before the script is run Dim FilenameRegExp 'String - A regular expression to find all files containing the previous day's date Dim CheckYear 'Integer - The year component of the previous day's date Dim CheckMonth 'Integer - The month component of the previous day's date Dim CheckDate 'Integer - The day component of the previous day's date Dim objFSO 'File System Object Dim objFolder 'Folder Object Dim inputFolder 'String - Folder/Directory containing the log files you need processing Dim outputFolder 'String - Folder/Directory where you want the output to go Dim colFiles 'Object representing list of files Dim objFile 'Object representing a single file Dim objShell 'Object representing a shell access Dim objExecObject 'Onject represneting an external process Dim tempFileName 'String - temporary file name used to identify files that were created yesterday Dim fileNameLength 'Int - the length of the file name being checked Dim fileNumber 'Int - the number attached at the end of the filename eg. 001 from ISALOG_20061101_WEB_001.MDF Dim inputFileName 'String - the filename to pass to the other vbscript Dim outputFileName 'String - the filename to output the file to. inputFolder = "D:\test" 'change as required outputFolder = "D:\test\processed" ' The DatePart function is a generic function that can retrieve any portion of a date or time value DateToCheck = DateAdd("d",-1,Date) CheckYear = DatePart("yyyy" , DateToCheck) 'Returns the year from the date-time value CheckMonth = DatePart("m" , DateToCheck) 'Returns the month of the year with January 1 being 1 and December 31 being 365 (366 during leap years). For example, February 1 returns 32 because it is the 32nd day of the year. CheckDate = DatePart("d" , DateToCheck) 'Returns the day of the month. For example, both April 17 and August 17 return 17. 'Set the filename(s) to Search for tempFileName = "ISALOG_" & CheckYear & CheckMonth & CheckDate Set objFSO = CreateObject("Scripting.FileSystemObject") Wscript.Echo "Checking status of directory " & inputFolder If objFSO.FolderExists(inputFolder) Then Set objFolder = objFSO.GetFolder(inputFolder) Else Wscript.Echo "Folder does not exist" End If Set colFiles = objFolder.Files Wscript.Echo "Checking for log files from " & DateToCheck For Each objFile in colFiles If LCase(Right(objFile.Name, 4)) = ".mdf" Then if InStr (objFile.Name, tempFileName) > 0 Then Wscript.Echo "Processing " & objFile.Name fileNameLength = Len(objFile.Name) 'Generate the ISALOG_20061101_WEB_000 part of the filename inputFileName = Left(objFile.Name, fileNameLength - 4) 'Change the 22 in the following line to 21, and the 2 to 3 if you need to expand from _01, 02 to _001, 002 filenames fileNumber = Mid(objFile.Name,22,2) if fileNumber = "02" Then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & FileNumber & ".txt" Else if fileNumber = "01" Then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & FileNumber & ".txt" Else If fileNumber = "00" then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & fileNumber & ".txt" End if Wscript.Echo "msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName 'set and run the parameters into CMD prompt Set objShell = WScript.CreateObject("WScript.Shell") Set objExecObject = objShell.Exec("msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName) End if End If Next Still getting no result when running on the server apart from when running from a CMD prompt. This results in a "not a recognised Win32 application"
|
|
| |
|
|
|
 |
RE: Complicated: read a filename if its yesterdays date... - 12/21/2006 2:45:10 AM
|
|
 |
|
| |
swerver
Posts: 27
Score: 0
Joined: 12/18/2006
Status: offline
|
this finished script now works: Option Explicit Dim DateToCheck 'Date - This will be calculated as the day before the script is run Dim FilenameRegExp 'String - A regular expression to find all files containing the previous day's date Dim CheckYear 'Integer - The year component of the previous day's date Dim CheckMonth 'Integer - The month component of the previous day's date Dim CheckDate 'Integer - The day component of the previous day's date Dim objFSO 'File System Object Dim objFolder 'Folder Object Dim inputFolder 'String - Folder/Directory containing the log files you need processing Dim outputFolder 'String - Folder/Directory where you want the output to go Dim colFiles 'Object representing list of files Dim objFile 'Object representing a single file Dim objShell 'Object representing a shell access Dim objExecObject 'Onject represneting an external process Dim tempFileName 'String - temporary file name used to identify files that were created yesterday Dim fileNameLength 'Int - the length of the file name being checked Dim fileNumber 'Int - the number attached at the end of the filename eg. 001 from ISALOG_20061101_WEB_001.MDF Dim inputFileName 'String - the filename to pass to the other vbscript Dim outputFileName 'String - the filename to output the file to. Dim runme 'string - the output CMD details. inputFolder = "D:\test" 'change as required outputFolder = "D:\test\processed" ' The DatePart function is a generic function that can retrieve any portion of a date or time value DateToCheck = DateAdd("d",-1,Date) CheckYear = DatePart("yyyy" , DateToCheck) 'Returns the year from the date-time value CheckMonth = DatePart("m" , DateToCheck) 'Returns the month of the year with January 1 being 1 and December 31 being 365 (366 during leap years). For example, February 1 returns 32 because it is the 32nd day of the year. CheckDate = DatePart("d" , DateToCheck) 'Returns the day of the month. For example, both April 17 and August 17 return 17. 'Set the filename(s) to Search for tempFileName = "ISALOG_" & CheckYear & CheckMonth & CheckDate Set objFSO = CreateObject("Scripting.FileSystemObject") Wscript.Echo "Checking status of directory " & inputFolder If objFSO.FolderExists(inputFolder) Then Set objFolder = objFSO.GetFolder(inputFolder) Else Wscript.Echo "Folder does not exist" End If Set colFiles = objFolder.Files Wscript.Echo "Checking for log files from " & DateToCheck For Each objFile in colFiles If LCase(Right(objFile.Name, 4)) = ".mdf" Then if InStr (objFile.Name, tempFileName) > 0 Then Wscript.Echo "Processing " & objFile.Name fileNameLength = Len(objFile.Name) 'Generate the ISALOG_20061101_WEB_000 part of the filename inputFileName = Left(objFile.Name, fileNameLength - 4) 'Change the 22 in the following line to 21, and the 2 to 3 if you need to expand from _01, 02 to _001, 002 filenames fileNumber = Mid(objFile.Name,22,2) if fileNumber = "02" Then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & FileNumber & ".txt" Else if fileNumber = "01" Then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & FileNumber & ".txt" Else If fileNumber = "00" then outputFileName = outputFolder & "\" & CheckYear & CheckMonth & CheckDate & "_" & fileNumber & ".txt" End if Wscript.Echo "msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName RunMe = "msdetotext.vbs " & inputFileName & " webproxylog " & outputFileName 'set and run the parameters into CMD prompt Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run(RunMe) End if End If Next It works... thanks for all your help people!
< Message edited by swerver -- 12/21/2006 2:59:52 AM >
|
|
| |
|
|
|
|
|