monitor logs for errors

Each time a Blackboard course is archived, there is a log file generated.  Actually a log and a detailed.log file.  If something goes wrong, errors are logged – and the bad one is “FATAL”.  This can be associated with a 2KB ZIP file, or no file at all.

If you get-content on the logs directory, you can use “select-string -Pattern ‘FATAL'” to look for fatal errors.  You can then report on the filename or accumulate counts of each class – files read and files with errors.

$fatalerrors = 0
get-childitem -path \\server\e$\logs|*details.txt|foreach{
# code block here, notice we didn't put the 
# gci directory into a variable, we just piped it.
}

Our code block looks like

$thepath = "\\server\e$\logs\" + $_.name 
# we want the name property from the fileinfo object
$error = (gc $thepath)|select-string -pattern "FATAL"
if ($error){
$_.name #  (write out the name of the file with the error)
$fataerrors++ 
}
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.