텍스트 파일의 마지막 줄 쿼리 VB Script (VBS) - SCOM SystemCenter2009. 7. 15. 14:59
Property[@Name='Message'] 를 이용해 문자열 검색
Alert Description
$Data/Context/Property[@Name='Message']$
-----------------------------------------------------------------------------------------------------
Dim oAPI, oBag, strMessage
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Set oArgs = WScript.Arguments
ParamCount = oArgs.Count
If ParamCount < 1 Then
Call oAPI.LogScriptEvent("StringCheck.vbs", 5009, 0, "Script aborted. Not enough parameters provided.")
WScript.Quit -1
End If
strMessage=getlastline(oArgs(0))
Call oBag.AddValue("Message", strMessage)
Call oAPI.Return(oBag)
function getlastline (ascfile)
set fs = createobject("scripting.filesystemobject")
set file = fs.GetFile(ascfile)
set stream = file.OpenAsTextStream
stream.skip file.size
line = stream.line
stream.close
set stream = file.OpenAsTextStream
for i=1 to line-2
stream.skipline
next
getlastline = stream.readline
if not stream.atendofstream then
getlastline = stream.readline
end if
end function