Last active
November 26, 2015 17:11
-
-
Save skunkie/8342f101e4c659015756 to your computer and use it in GitHub Desktop.
VBS script for Check_MK check fileinfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Dim config, configFile, f, ffilename, filename, fmtime, fso, mtime, tzo, N, Y, M, D | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
configFile = fso.GetParentFolderName(fso.GetParentFolderName(Wscript.ScriptFullName)) & "\fileinfo.cfg" | |
If NOT fso.FileExists(configFile) Then | |
WScript.Quit | |
End If | |
WScript.Echo "<<<fileinfo:sep(124)>>>" | |
Function GetTimeZoneOffset() | |
Const sComputer = "." | |
Dim oWmiService : Set oWmiService = _ | |
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ | |
& sComputer & "\root\cimv2") | |
Dim cTimeZone : Set cTimeZone = _ | |
oWmiService.ExecQuery("Select * from Win32_TimeZone") | |
Dim oTimeZone | |
For Each oTimeZone in cTimeZone | |
GetTimeZoneOffset = oTimeZone.Bias / 60 | |
Exit For | |
Next | |
End Function | |
Function GetUnixTimeStamp(time) | |
GetUnixTimeStamp = DateDiff("s", "01/01/1970 00:00:00", time) | |
End Function | |
tzo = GetTimeZoneOffset() | |
N = Now() | |
WScript.Echo GetUnixTimeStamp(DateAdd("h", -tzo, N)) | |
Y = DatePart("yyyy", N) | |
M = Right("0" & DatePart("m", N), 2) | |
D = Right("0" & DatePart("d", N), 2) | |
Set config = fso.OpenTextFile(configFile, 1) | |
Do Until config.AtEndOfStream | |
filename = config.Readline | |
ffilename = filename | |
filename = Replace(filename, "%Y", Y) | |
filename = Replace(filename, "%M", M) | |
filename = Replace(filename, "%D", D) | |
If fso.FileExists(filename) Then | |
Set f = fso.GetFile(filename) | |
mtime = DateAdd("h", -tzo, f.DateLastModified) | |
fmtime = GetUnixTimeStamp(mtime) | |
WScript.Echo ffilename & "|" & f.size & "|" & fmtime | |
End If | |
Loop | |
WScript.Quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment