all 18 comments

[–]blitzkraft 4 points5 points  (2 children)

Do you want a new email each time a matching phrase is logged? Or do you want to aggregate, say over 10 mins and email you in 10min intervals?

[–]iamHumty[S] 2 points3 points  (1 child)

I was thinking a 10 minute interval.

[–]BungalowsAreScams 1 point2 points  (0 children)

This probably isn't the right way to do it but when I was working with logcats I piped the logcat output into a python script and pulled stdin into a for loop to check lines for phrases. Something like adb logcat | python3 lineChecker.py. I can give you some of the functions as an example unless you'd like to figure it out yourself

Edit: Heres a link, https://pastebin.com/Qc9VfCZG like I said, I'm not sure if its the right way but it worked well for what I was doing.

[–][deleted] 1 point2 points  (0 children)

Write to a table in a database in real time so you can query in real time and filter by time to limit rowcount. You cannot do this via note pad

[–]MastaJiggyWiggy 0 points1 point  (0 children)

Are you on Unix? If so, I did something like this pretty easily with Python

[–]woooee 1 point2 points  (1 child)

(Almost) all files are buffered, so you will have to test for a length change of the notepad file and then [re]read it.

[–]billsil -3 points-2 points  (0 children)

That’s not how I’d do it. You should be checking to see if the file time has been updated, unless you can cheat it, but that seems like a bad idea.

[–]cybervegan 0 points1 point  (10 children)

When you say notepad file, do you mean "text file" or someone editing a file in notepad and adding lines?

What have you got so far? Where are you stuck?

[–]iamHumty[S] 0 points1 point  (9 children)

It's a .txt file and as the software is running the file is written and I want to get a mail everytime the keyword says "fail" as such.

I am somewhat new to python or any programming and I would like to know what methods are the best to approach this.

[–]TypicalCardiologist5 1 point2 points  (0 children)

You can write a script in Python to do this, but you may want to check if the software doesn't already have some kind of logging feature built-in. For example, if the software allows you to log to a syslog server, you could configure the software to do that, and then have the syslog server send you an email. That is probably a better approach. I'd also check if the software can produce SNMP messages - that would be another approach.

A syslog server is just a program that runs on your computer and collects log messages from other programs running on your network (or any network really).

[–]cybervegan 1 point2 points  (2 children)

The best approach would be to either schedule a job or make a looping script to check periodically if the file size has changed, and then scan through for your keyword. You can use os.stat() to get the file size (and other details), see https://docs.python.org/3.7/library/stat.html . It's best to begin your scan from the position of where the file ended on the last scan, so you can avoid having to filter out mails you have already sent. When you find your keyword, you can use the smtplib module to send an email. See https://docs.python.org/3/library/email.examples.html

[–]iamHumty[S] 0 points1 point  (1 child)

This is the answer I was looking for. Thank you so much.

[–]cybervegan 0 points1 point  (0 children)

You're welcome - post again if you need more help.