Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find a content within text files on remote pc's ?

Status
Not open for further replies.

Goppi

Programmer
Jun 21, 2003
40
GB
I'm looking for the best way to find a specific string (e.g. "directory") within text files where the name applies to a certain convention (e.g. "*data*.txt") that are stored in multiple sub-directories underneath a certain path (e.g. "C:\app") whereas the last sub-folder has always a fixed name (e.g. "data" in "C:\app\test1\data") on all pc's within a certain ip-range from a mgmt. console pc - Got that ;-).

Any ideas or tips?

Pete
 
Is there really no tool available ? Or has nobody ever done that ?

Goppi
 
'author richard moyle

'On Error Resume Next
SetLocale("en-us")

Dim FSO, WshShell, refWMIService, refDirectory
Dim strDir

'default objects
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set dicResults = Wscript.CreateObject("Scripting.Dictionary")
'use wmi to get all files with the uls* name


strDir = "f:\"
Set objDir = FSO.GetFolder(strDir)

getInfo(objDir)




'write results to a logfile

Set tsResults = FSO.CreateTextFile("c:\auditresults.log", True)

For Each aKey In dicResults
tsResults.WriteLine aKey & "=" & dicResults.Item(aKey)
Next

tsResults.Close
Set tsResults = Nothing

'end of script part


Function getInfo(pCurrentDir)


For Each aItem In pCurrentDir.Files
'wscript.Echo aItem.Name
If LCase(Left(Cstr(aItem.Name), 3)) = "uls" Then
checkFile(aItem)
End If
Next


For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next


End Function

'check the file contents for what we are looking for!!!
Function checkFile(pFile)
On Error Resume Next
Dim strUser, tsLog, sLine, lPos, strMapping

Wscript.Echo pFile.Path & " from here"
Set tsLog = FSO.OpenTextFile(CStr(pFile.Path), 1, False)
Do While Not tsLog.AtEndOfStream
sLine = Trim(LCase(tsLog.ReadLine))
If InStr(sLine, "over 3 patterns old") Then
msgbox "over3;" & pFile.Name
'dicResults.Add pFile.Name, "1"
End If

If InStr(sLine, "unable to determine current pattern") Then
msgbox "none;" & pFile.Name
'dicResults.Add pFile.Name, "1"
End If
Loop

tsLog.Close
Set tsLog = Nothing

End Function
 
i should explain.
given a root folder this script loops through every sub folder and every file. if it finds a file of a certain type/name it opens that file and then searches for a specified string, if it is found it does something.

all you have to do is loop through your computers as well.
you might want to read all the ipaddress and then connect to their c$ share?? or you might want to go with WMI and get a ref to a remote computer that way
 
Thanks mrmovie, that helps me a lot - I really appriciate that...

cheers,

Goppi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top