Author Posts

April 20, 2016 at 5:08 am

I am trying to write a script that will look at a log file. There is a line in the file called TOTAL_TIME= . I would like to send an email if TOTAL_TIME is greater than 50000
Below is a sample of what the file looks like.

root-aborted=false
innerScript=false
START_TIME=1461098129524
TOTAL_TIME=23406
scriptSection=Creation
root-storeVersion=1

April 20, 2016 at 5:18 am

What do you need in the email body? Is 'Total_time' on multiple lines in a log file? How many log files do you need to parse?

April 20, 2016 at 5:22 am

I would like the body to say that the search time is at "TOTAL_TIME"
The Total time is only on one line in the text file, I only need to do this on one log file.

Thanks

April 20, 2016 at 5:57 am

get-content c:\temp\logfile.log | ? {$_ -match 'total_time='} | % {
	$totaltime = $_.split('=')[-1]
	$somenumber = 50000
	if ($totaltime -gt $somenumber) {
		#send-mailmessage ...
	}
}

April 20, 2016 at 7:34 am

For some reason the logic will only work up to 9999 If I try 50000 it seem to work.. Is this limited to 4 digits? Here is my script. If I change the gt 50000 to 5000 it works. The value in the log file is TOTAL_TIME=7640

Get-Content 'c:\test\overview.properties' |? {$_ -match 'total_time='} | % {
$totaltime = $_.split('=')[-1]
if ($totaltime -gt50000)
{
Send-MailMessage -From test-Subject "Searches are above 50000" -To test -Body "test" -SmtpServer xxx.xx.com
}
ELSE
{
Write-host "Not above 50000"

April 20, 2016 at 9:02 am

Cast your totaltime variable as an integer and your code should work.

Get-Content '.\logfile' | ForEach-Object {
    [void]($_ -match 'TOTAL_TIME=.*')
    $time = ($Matches[0] -split '=')[-1]
    If ([int]$time -gt 9999){Send-MailMessage}
}

April 20, 2016 at 9:41 am

Thanks. It works like a charm!!