gera log para cada dia .vbs

0

Estou tentando criar um arquivo de log para o dia com esse script

hostIp      = wscript.arguments(0)
logfilename = wscript.arguments(1)
Set fso     = CreateObject("Scripting.FileSystemObject")
Set Shell   = CreateObject("Wscript.Shell")
' OpenTextFile Method requires a Const value
' (Over)Write = 2  Append = 8  
    d = Day(Now) 
    m = Month(Now)  
    y = Year(Now)
    myDateFormat= d & "-" & m & "-" & y 
Set logfile = fso.OpenTextFile(logfilename & " " & myDateFormat & ".log", 8, True)
shellstring = "%comspec% /c ping -t -f -l 32 -w 1000 " & hostIP
Set oExec   = Shell.Exec(shellstring)
wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt"
Do While oExec.StdOut.AtEndOfStream <> True
      pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine
'      If InStr(pingline, "TTL=") = 0 Then
         logfile.WriteLine(pingline)
'      End If
Loop

Eu achei que estava tudo bem, mas executei por 3 dias e há apenas um arquivo em vez de 3. Alguma idéia sobre o que está errado com o script? btw eu corro este script em cmd com esta linha

FileName ip logname.log
    
por Rildo Gomez 23.10.2017 / 19:21

1 resposta

0

Isso ajuda:

dim objShell : set ObjShell  = CreateObject("Wscript.Shell")
dim objFso   : set objFso    = CreateObject("Scripting.FileSystemObject")

dim shellstring : shellstring = "%comspec% /c ping -t -f -l 32 -w 1000 " & wscript.arguments(0)

dim oExec : set oExec = ObjShell.Exec(shellstring)

do while oExec.StdOut.AtEndOfStream <> true
  log( oExec.StdOut.ReadLine )
loop

function log(strLineIn)

  myDateFormat= Day(Now) & "-" & Month(Now) & "-" & Year(Now)

  dim logfile : set logfile = objFso.OpenTextFile(wscript.arguments(1) & " " & myDateFormat & ".log", 8, True)

  if instr(strLineIn, "TTL") > 0 then
    logfile.writeline date() & "-" & time() & ": " & strLineIn
  end if

  logfile.close

end function
    
por 23.10.2017 / 21:47