Darren Matheson
Darren Matheson

Reputation: 111

Powershell to Check File *Not* Modified

So I'm a Linux guy, been doing this for a while, and now the boss has asked me to look at something on a Windows 2008 server. Basically, there's a Java app that does something, and occasionally, it hangs. The thing is that unless someone is actually watching it, there is no hint that it has hung.

The application writes to a logfile on the 2008 server, updating it every five minutes. If the application hangs, it (obviously) stops writing to the logfile.

I would like a way to check that file every say, fifteen minutes and if the file has not been modified in the past fifteen minutes, send an alert.

Can this be done? Is it horrendously complicated? Would it be easier to write it in bash/cygwin?

Many thanks.

Upvotes: 0

Views: 961

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200373

Create a scheduled task that runs a PowerShell script containing something like this every 5 minutes or so:

$logfile = 'C:\path\to\your.log'
$threshold = (Get-Date).AddMinutes(-15)

if ((Get-Item $logfile).LastWriteTime -lt $threshold) {
    # send alert
}

Upvotes: 2

Related Questions