Simulating tail -f in Logparser

  • Thread starter Thread starter KayZer Soze
  • Start date Start date
K

KayZer Soze

In Linux Shell, the 'tail -f' command can be used to show an log file, as
lines are beeing added, dynamically. As the linnes are added to the end of
file, the lines are showed.
This can be done with MS logparser?
 
Hello, KayZer:
On Thu, 17 Feb 2005 14:40:08 -0300: you wrote...

KS> In Linux Shell, the 'tail -f' command can be used to show an log file,
KS> as lines are beeing added, dynamically. As the linnes are added to the
KS> end of file, the lines are showed.
KS> This can be done with MS logparser?
KS>

Logparser runs a single query. Try tail from
http://unxutils.sourceforge.net/
or
GUI based tail here http://tailforwin32.sourceforge.net/

Regards, Paul R. Sadowski [MVP].
 
Paul said:
Hello, KayZer:
On Thu, 17 Feb 2005 14:40:08 -0300: you wrote...

KS> In Linux Shell, the 'tail -f' command can be used to show an log file,
KS> as lines are beeing added, dynamically. As the linnes are added to the
KS> end of file, the lines are showed.
KS> This can be done with MS logparser?
KS>

Logparser runs a single query. Try tail from
http://unxutils.sourceforge.net/
or
GUI based tail here http://tailforwin32.sourceforge.net/

Regards, Paul R. Sadowski [MVP].

yesterday i wrote a script that does exactly that

' Purpose: monitor a file and report the changed lines when modified
' similar to unix's tail -f
' Programmer: (e-mail address removed)
' Last Modified: 04.06.05
' Usage: Drag and drop a file onto the script.

numARGS = ((Wscript.Arguments.count) - 1)
sleepTime = 5
nSecs = sleepTime * 100

' get the filename
for i = 0 to numARGS step 1
fileName = Wscript.Arguments(i)
next

currentSize = getFileSize(fileName)
currentNumLines = getLineCount(fileName)
set oFso = CreateObject("Scripting.FileSystemObject")

while 1
nSize = getFileSize(fileName)
if (nSize > currentSize) then
currentSize = nSize
Set ts = oFso.OpenTextFile(fileName, 1, False)
Set contentsDict = CreateObject("Scripting.Dictionary")

While Not ts.atendofstream
contentsDict.Add i, ts.ReadLine
i = i + 1
Wend
i = 0

ts.Close
Set ts = Nothing
numLines = contentsDict.Count
startLine = currentNumLines
for key = startLine to numLines step 1
tail = tail & VBCRLF & contentsDict(key)
next
' msgbox tail
wscript.echo tail
tail = ""
currentNumLines = getLineCount(fileName)
end if
WScript.Sleep nSecs
wend


Function getFileSize(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.size
getFileSize = s
End Function

Function getLineCount(filespec)
v = 0
set p_oFso = CreateObject("Scripting.FileSystemObject")
set p_ts = p_oFso.OpenTextFile(filespec, 1, False)
Set p_contentsDict = CreateObject("Scripting.Dictionary")
While Not p_ts.atendofstream
p_contentsDict.Add v, p_ts.ReadLine
v = v + 1
Wend
getLineCount = p_contentsDict.Count
End Function
 
Hello, ews:
On Fri, 08 Apr 2005 16:37:40 -0700: you wrote...

e> yesterday i wrote a script that does exactly that
e>
e> ' Purpose: monitor a file and report the changed lines when modified
e> ' similar to unix's tail -f

Thanks for posting the code.

e> ' Programmer: (e-mail address removed)
e> ' Last Modified: 04.06.05
e> ' Usage: Drag and drop a file onto the script.
e>
e> numARGS = ((Wscript.Arguments.count) - 1)
e> sleepTime = 5
e> nSecs = sleepTime * 100
e>
e> ' get the filename
e> for i = 0 to numARGS step 1
e> fileName = Wscript.Arguments(i)
e> next
e>
e> currentSize = getFileSize(fileName)
e> currentNumLines = getLineCount(fileName)
e> set oFso = CreateObject("Scripting.FileSystemObject")
e>
e> while 1
e> nSize = getFileSize(fileName)
e> if (nSize > currentSize) then
e> currentSize = nSize
e> Set ts = oFso.OpenTextFile(fileName, 1, False)
e> Set contentsDict = CreateObject("Scripting.Dictionary")
e>
e> While Not ts.atendofstream
e> contentsDict.Add i, ts.ReadLine
e> i = i + 1
e> Wend
e> i = 0
e>
e> ts.Close
e> Set ts = Nothing
e> numLines = contentsDict.Count
e> startLine = currentNumLines
e> for key = startLine to numLines step 1
e> tail = tail & VBCRLF & contentsDict(key)
e> next
e> ' msgbox tail
e> wscript.echo tail
e> tail = ""
e> currentNumLines = getLineCount(fileName)
e> end if
e> WScript.Sleep nSecs
e> wend
e>
e> Function getFileSize(filespec)
e> Dim fso, f, s
e> Set fso = CreateObject("Scripting.FileSystemObject")
e> Set f = fso.GetFile(filespec)
e> s = f.size
e> getFileSize = s
e> End Function
e>
e> Function getLineCount(filespec)
e> v = 0
e> set p_oFso = CreateObject("Scripting.FileSystemObject")
e> set p_ts = p_oFso.OpenTextFile(filespec, 1, False)
e> Set p_contentsDict = CreateObject("Scripting.Dictionary")
e> While Not p_ts.atendofstream
e> p_contentsDict.Add v, p_ts.ReadLine
e> v = v + 1
e> Wend
e> getLineCount = p_contentsDict.Count
e> End Function

Regards, Paul R. Sadowski [MVP].
 
Back
Top