Friday, October 12, 2012

Check_Churn script;This script will basically to see how much the log files are changing over a user defined period of time

Check_Churn script;This script will basically to see how much the log files are changing over a user defined period of time.
It's useful to check how if there are any delay in getting a logfile updated from the start of the file o the end of the file at some instance(depends on the schedule time of the script as well).

Syntax to follow: C:\>cscript /nologo "c:\Documents and Settings\bdhinakaran\Desktop\VbScript\chec
k_churn.vbs" -d "c:\\" -p "(iiCFDFXLIVE-SyslogHub-3.3.3-instance1\[(\d)\]).log"
-c 90



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'On Error Resume Next

adir = Wscript.Arguments.Item(0)
dir = Cstr(Wscript.Arguments.Item(1))
aPatternMatch = Wscript.Arguments.Item(2)
PatternMatch = Cstr(Wscript.Arguments.Item(3))
acri = Wscript.Arguments.Item(4)
cri = CLng(Wscript.Arguments.Item(5))


If adir = "-d" and aPatternMatch = "-p" and acri = "-c" Then
 
 
   Const adVarChar = 200
   Const MaxCharacters = 255
   today = now()
   Set DataList = CreateObject("ADOR.Recordset")
   DataList.Fields.Append "FileName", adVarChar, MaxCharacters
   DataList.Fields.Append "FileDateCreated", adVarChar, MaxCharacters
   DataList.Open
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set hash = CreateObject ("Scripting.Dictionary")
   If fso.FolderExists(dir) Then
    Set f = fso.GetFolder(dir)
    Set fc = f.Files
     
    For Each file in fc
      's = s & file.name & " " & "DateCreated "& file.DateCreated
 'hash.add file.name, file.DateCreated
      's = s &   VbNewLine
 'count = count + 1

 Set myRegExp = New RegExp
      myRegExp.IgnoreCase = True
      myRegExp.Global = True
      myRegExp.Pattern = patternMatch
      'Wscript.Echo "Pattern Match:" & patternMatch
      Set myMatches = myRegExp.Execute(file.Name)
      If myMatches.count > 0 Then
    DataList.AddNew
    DataList("FileName") = Cstr(file.name)
    DataList("FileDateCreated") = file.DateCreated
    DataList.Update
count = count + 1
'Wscript.Echo "Matched Pattern:" & patternMatch
 End If

    Next
      'Wscript.Echo "No Pattern Match Found in the specified Directory:" &dir
  'Wscript.Echo "Total Files:"&count
   Else
Wscript.Echo "Folder doesn't exists. Please check the path"
Wscript.Quit(2)
   End If

If count > 1 Then
DataList.Sort = "FileName asc" 'sort the disconnected recordset to asc by default it sorts to ascending if needed can sort to desc
DataList.MoveFirst
diff1 = DateDiff("s",DataList.Fields.Item("FileDateCreated"),today)
DataList.MoveLast
diff2 = DateDiff("s",DataList.Fields.Item("FileDateCreated"),today)
rdiff = diff1 - diff2
'Wscript.Echo "Real diff in Second for the FirstFile and LastFile:" & rdiff &"sec"

'Displays the overall fields
'DataList.MoveFirst
'Do Until DataList.EOF
' Wscript.Echo DataList.Fields.Item("FileName") & vbTab & DataList.Fields.Item("FileDateCreated")
' DataList.MoveNext
'Loop

If cri > rdiff Then
Wscript.Echo "Creation Time of the First Log file and Last LogFile is less than the user-defined time:" & rdiff &"sec" &"in the directory: " &dir
Wscript.quit(0)

Else
Wscript.Echo "Is more than the user-defined time: " & rdiff &" sec " & " in the directory: " &dir
Wscript.Quit(2)
End If

'keys = hash.Keys
'items = hash.Items
'for i = 0 to hash.Count - 1
'wscript.echo Keys(i) & " = " & hash.item(Keys(i))
'next

'diff1 = DateDiff("s",hash.item(Keys(0)),today)
'diff2 = DateDiff("s",hash.item(Keys(hash.Count - 1)),today)

'Wscript.Echo "The First File Difference with the today's date:" & diff1
'Wscript.Echo "The Last File Difference with the today's date:" & diff2
'rdiff = diff1 - diff2
'Wscript.Echo s
'Wscript.Echo "Real diff in Second for the FirstFile and LastFile:" & rdiff &"sec"
'Wscript.Echo "Total Files:" & hash.Count
     Else
'DataList.MoveFirst
'Do Until DataList.EOF
'Wscript.Echo DataList.Fields.Item("FileName") & vbTab & DataList.Fields.Item("FileDateCreated")
'DataList.MoveNext
'Loop
Wscript.Echo "We have single record or file in the specified Directory or no files of the patten match specified: " & dir
Wscript.Quit(2)
End If
  Else
   Wscript.Echo "Please follow the pattern: check_churn.vbs -d <directory> -p <pattern> -c <error_sec> "
   Wscript.echo "This script will basically to see how much the log files are changing over a user defined period of time"
   Wscript.Quit(2)
End If

No comments:

Post a Comment